> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orbitrage.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Vercel AI SDK

> Route + trace the Vercel AI SDK through Orbitrage.

Create an OpenAI-compatible provider pointed at the gateway, then use it as your
model with `generateText` / `streamText`.

## Install

```bash theme={null}
npm install orbitrage@latest ai @ai-sdk/openai
```

## Generate text

Pass your end-user id via the provider's `headers`. Use `provider.chat(...)` so
calls go to the `/chat/completions` endpoint Orbitrage routes.

```typescript theme={null}
import { orbitrage } from "orbitrage";
await orbitrage.init({ apiKey: process.env.ORBITRAGE_API_KEY, userId: "customer_42" });

import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";

const provider = createOpenAI({
  baseURL: "https://api.orbitrage.ai/v1",
  apiKey: process.env.ORBITRAGE_API_KEY,
  headers: { "x-orbitrage-end-user-id": "customer_42" },
});

const { text } = await generateText({
  model: provider.chat("glm-5.2"),     // direct model — or "minimax-m3"; "auto" to route
  prompt: "Explain routing in one line.",
  maxOutputTokens: 512,
});
console.log(text);
```

## Stream text

```typescript theme={null}
import { streamText } from "ai";

const result = streamText({
  model: provider.chat("minimax-m3"),
  prompt: "Count from 1 to 5.",
  maxOutputTokens: 64,
});
for await (const delta of result.textStream) process.stdout.write(delta);
```

Tool calling works exactly as the AI SDK documents — Orbitrage doesn't change the
API. For hosted [managed tools](/concepts/tools-gateway), call the gateway
directly or via the raw OpenAI client.

<Tip>
  Pin a **direct model** (`glm-5.2`, `minimax-m3`) for predictable
  behavior; switch the string to `"auto"` to let Orbitrage route.
</Tip>
