# Vercel AI SDK

Source: https://staging-docs.aiand.com/integrations/vercel-ai/

The Vercel AI SDK works against ai& through the `@ai-sdk/openai` provider with a custom base URL.

## Setup

```bash
npm install ai @ai-sdk/openai
```

```ts

export const aiand = createOpenAI({
  baseURL: "https://api.aiand.com/v1",
  apiKey: process.env.AIAND_API_KEY,
});
```

## Generate text

```ts


const { text } = await generateText({
  model: aiand("openai/gpt-oss-120b"),
  prompt: "Tell me a haiku about Tokyo.",
});

console.log(text);
```

## Stream to the browser (Next.js App Router)

```ts
// app/api/chat/route.ts


export async function POST(req: Request) {
  const { messages } = await req.json();
  const result = streamText({
    model: aiand("openai/gpt-oss-120b"),
    messages,
  });
  return result.toDataStreamResponse();
}
```

```tsx
// app/page.tsx
"use client";

export default function Page() {
  const { messages, input, handleInputChange, handleSubmit } = useChat();
  return (
    <form onSubmit={handleSubmit}>
      {messages.map((m) => (
        <div key={m.id}>{m.role}: {m.content}</div>
      ))}
      <input value={input} onChange={handleInputChange} />
    </form>
  );
}
```

## Tools

```ts


const result = await generateText({
  model: aiand("openai/gpt-oss-120b"),
  tools: {
    getWeather: tool({
      description: "Get current weather",
      parameters: z.object({ city: z.string() }),
      execute: async ({ city }) => `Sunny in ${city}, 22°C`,
    }),
  },
  prompt: "What's the weather in Tokyo?",
});
```

<Aside type="tip">
  For React Server Components UI streaming with `useUIState` / `streamUI`, the same `aiand` provider works without changes.
</Aside>
