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

# Vercel AI SDK

> Generate and stream RedPill responses in TypeScript applications.

Use the AI SDK's OpenAI-compatible provider with RedPill.

```bash theme={null}
npm install ai @ai-sdk/openai-compatible
export REDPILL_AI_API_KEY="YOUR_API_KEY"
```

## Configure the provider

```typescript theme={null}
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

const apiKey = process.env.REDPILL_AI_API_KEY;
if (!apiKey) throw new Error("REDPILL_AI_API_KEY is required");

export const redpill = createOpenAICompatible({
  name: "redpill",
  apiKey,
  baseURL: "https://api.redpill.ai/v1",
});
```

Use `.chatModel()` with an exact model ID. The provider sends that ID without adding a prefix.

## Generate text

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

import { redpill } from "./redpill";

const { text } = await generateText({
  model: redpill.chatModel("z-ai/glm-5.2"),
  prompt: "Explain attestation in one sentence.",
});
console.log(text);
```

## Stream from a route

```typescript app/api/generate/route.ts theme={null}
import { streamText } from "ai";

import { redpill } from "../../../redpill";

export async function POST(request: Request) {
  const body: unknown = await request.json().catch(() => null);
  if (
    typeof body !== "object" ||
    body === null ||
    !("prompt" in body) ||
    typeof body.prompt !== "string" ||
    body.prompt.trim().length === 0
  ) {
    return Response.json({ error: "A non-empty prompt is required" }, { status: 400 });
  }

  const result = streamText({
    model: redpill.chatModel("z-ai/glm-5.2"),
    prompt: body.prompt.trim(),
  });
  return result.toTextStreamResponse();
}
```

Keep the RedPill key on the server. Validate tool arguments and bound multi-step tool loops.

## Verification boundary

The base-URL configuration does not verify ACI locally. Node and Bun applications can pass
`connectAci().fetch` to `createOpenAICompatible`, then audit the retained receipt after generation.
See the [verified Node and Bun transport](/guides/integrations/openai-sdk#verified-node-and-bun-transport).

## References

* [AI SDK OpenAI-compatible provider](https://ai-sdk.dev/providers/openai-compatible-providers)
* [AI SDK `streamText`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text)
* [AI SDK UI chat](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot)
* [RedPill function calling](/guides/function-calling)
