> For the complete documentation index, see [llms.txt](https://docs.cortecs.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cortecs.ai/integration-examples/tooling/vercel-ai-sdk.md).

# Vercel AI SDK

The Vercel AI SDK supports both the Responses API and OpenAI-compatible Chat Completions. Use Responses for new agent workflows.

## Responses API

Install the required packages:

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

Configure the OpenAI provider with the Cortecs base URL:

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

const cortecs = createOpenAI({
  name: "cortecs",
  apiKey: process.env.CORTECS_API_KEY,
  baseURL: "https://api.cortecs.ai/v1",
});

const { text } = await generateText({
  model: cortecs.responses(process.env.CORTECS_MODEL!),
  prompt: "Explain model routing in two sentences.",
});

console.log(text);
```

Choose a model that advertises the capabilities your application uses in the [Models API](/api-overview/models.md).

## Chat Completions fallback

If a workflow or middleware expects Chat Completions, use the OpenAI-compatible provider:

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

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

const cortecs = createOpenAICompatible({
  name: "cortecs",
  apiKey: process.env.CORTECS_API_KEY,
  baseURL: "https://api.cortecs.ai/v1",
});

const { text } = await generateText({
  model: cortecs.chatModel(process.env.CORTECS_MODEL!),
  prompt: "Explain model routing in two sentences.",
  providerOptions: {
    cortecs: {
      preference: "balanced",
    },
  },
});

console.log(text);
```

Provider options are forwarded in the request body by the OpenAI-compatible provider. See [Advanced Usage](/routing/advanced-usage.md) for the Cortecs routing fields you can pass.

See the Vercel AI SDK documentation for the [OpenAI provider](https://ai-sdk.dev/providers/ai-sdk-providers/openai) and [OpenAI-compatible providers](https://ai-sdk.dev/providers/openai-compatible-providers).
