Iteration Layer
Products
Use Cases
Resources
Pricing
Documentation navigation

Vercel AI SDK

Vercel AI SDK is a TypeScript toolkit for AI applications and agents. Use Iteration Layer as backend tools when a chat app or agent needs to process files, extract structured data, or generate documents and images.

Wrap the official TypeScript SDK in AI SDK tools. Keep the Iteration Layer API key on the server side and expose only task-specific tools to the model.

Install

npm install ai zod iterationlayer

Example Tool

import { tool } from "ai";
import { z } from "zod";
import { IterationLayer } from "iterationlayer";

const client = new IterationLayer({
  apiKey: process.env.ITERATION_LAYER_API_KEY!,
});

export const extractInvoiceTool = tool({
  description: "Extract invoice fields from a PDF or image URL.",
  inputSchema: z.object({
    fileUrl: z.string().url(),
  }),
  execute: async ({ fileUrl }) => {
    return client.extractDocument({
      files: [
        {
          type: "url",
          name: "invoice.pdf",
          url: fileUrl,
        },
      ],
      schema: {
        fields: [
          { name: "vendor", type: "TEXT", description: "Vendor name" },
          { name: "invoice_number", type: "TEXT", description: "Invoice number" },
          { name: "total", type: "CURRENCY_AMOUNT", description: "Total amount" },
        ],
      },
    });
  },
});

Production Guidance

Expose business-level tools instead of raw generic API wrappers:

  • extractInvoiceTool
  • convertPolicyToMarkdownTool
  • generateApprovalPdfTool
  • createSpreadsheetExportTool

This keeps prompts shorter, avoids leaking unnecessary parameters to the model, and makes tool behavior easier to test.

For generated files, return the Iteration Layer binary response to your route handler and store it in object storage or return it as a download. Binary outputs use the same shape across document, image, and sheet generation: a buffer plus MIME type.