# Vercel AI SDK Integration

URL: https://interfaze.ai/docs/vercel-ai-sdk

Interfaze supports the Chat Completion API standard, so you can use it out of the box with the Vercel AI SDK by pointing it to Interfaze's base URL and API key.

## Installation

These examples use Vercel AI SDK v6 (`ai@^6.0.0` and `@ai-sdk/openai@^3.0.0`).

```tabs
language-typescript

tab-npm / yarn
npm install ai @ai-sdk/openai
# or
yarn add ai @ai-sdk/openai
```

## Official Documentation

- [Vercel AI SDK Documentation](https://ai-sdk.dev/docs/introduction)
- [Vercel OpenAI Integration](https://ai-sdk.dev/providers/ai-sdk-providers/openai#openai-provider)
- [Vercel Stream](https://ai-sdk.dev/docs/foundations/streaming#streaming)

> **Note:** Interfaze supports the Chat Completion API standard and not the Response API standard.

## Basic Setup

```tabs
language-typescript

tab-Vercel AI SDK
import { createOpenAI } from "@ai-sdk/openai";

const interfaze = createOpenAI({
  baseURL: "https://api.interfaze.ai/v1",
  apiKey: "<your-api-key>",
});
```

## Examples

### Text Generation

```tabs
language-typescript

tab-Vercel AI SDK
import { generateText } from "ai";

const { text } = await generateText({
  model: interfaze.chat("interfaze-beta"),
  prompt: "Write a short story about a robot learning to paint",
});

console.log(text);
```

### Structured Output

Learn more about [structured output](https://interfaze.ai/docs/structured-output).

```tabs
language-typescript

tab-Vercel AI SDK
import { generateText, Output } from "ai";
import { z } from "zod";

const weatherSchema = z.object({
  city: z.string().describe("The name of the city"),
  temperature_celsius: z.number().describe("Current temperature in Celsius"),
  condition: z.string().describe("Weather condition, e.g. sunny, rainy, cloudy"),
});

const { output } = await generateText({
  model: interfaze.chat("interfaze-beta"),
  output: Output.object({ schema: weatherSchema }),
  prompt: "What is the current weather in Tokyo?",
});

console.log(output);
```

### Image / File Input

```tabs
language-typescript

tab-Vercel AI SDK
import { generateText } from "ai";

const { text } = await generateText({
  model: interfaze.chat("interfaze-beta"),
  messages: [
    {
      role: "user",
      content: [
        { type: "text", text: "What is in this image?" },
        {
          type: "image",
          image: new URL("https://r2public.jigsawstack.com/interfaze/examples/construction.png"),
        },
      ],
    },
  ],
});

console.log(text);
```

### Streaming

Learn more about [streaming](https://interfaze.ai/docs/streaming).

```tabs
language-typescript

tab-Vercel AI SDK
import { streamText } from "ai";

const { textStream } = await streamText({
  model: interfaze.chat("interfaze-beta"),
  prompt: "Write a short story about a robot learning to paint",
});

for await (const delta of textStream) {
  process.stdout.write(delta);
}
```

### Function Calling

Learn more about [function calling](https://interfaze.ai/docs/function-calling).

```tabs
language-typescript

tab-Vercel AI SDK
import { generateText, tool, stepCountIs } from "ai";
import { z } from "zod";

const { text } = await generateText({
  model: interfaze.chat("interfaze-beta"),
  prompt: "What's the weather like in San Francisco?",
  tools: {
    weather: tool({
      description: "Get the weather in a location",
      inputSchema: z.object({
        location: z.string().describe("The location to get the weather for"),
      }),
      execute: async ({ location }) => ({
        location,
        temperature: 72 + Math.floor(Math.random() * 21) - 10,
      }),
    }),
  },
  stopWhen: stepCountIs(5),
  toolChoice: "auto",
});

console.log(text);
```
