[← Developer docs](https://aictrlx.ru/docs)

Integration

# Vercel AI SDK with aictrlx

The Vercel AI SDK connects to aictrlx through `createOpenAI` with its `baseURL`: `generateText`, `streamText` and tools in TypeScript on the models of the catalog.

## Setup

### Put the key in an environment variable

Every example below reads the key from `AICTRLX_API_KEY`, so it never ends up in your code.

Shell

```
export AICTRLX_API_KEY="aictrlx_live_..."
```

Use `createOpenAI` with `baseURL` and the `.chat()` model factory: this API implements Chat Completions, not the Responses API.

Install

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

TypeScript

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

const aictrlx = createOpenAI({
  baseURL: "https://aictrlx.ru/v1",
  apiKey: process.env.AICTRLX_API_KEY,
});

// aictrlx.chat(...) uses the Chat Completions API; plain aictrlx(...) would call the Responses API.
const { text, response } = await generateText({
  model: aictrlx.chat("auto"),
  prompt: "Explain vector databases in two sentences.",
});
console.log(text);
console.log(response.modelId); // the model that actually answered
```

## Which model to use

-   Use the `.chat()` model factory: aictrlx implements Chat Completions, not the Responses API.
-   `auto`, `fast`, `smart` and `coding` work as model names, as does any id from the models page.

[Models and prices →](https://aictrlx.ru/models)

## What it costs

You pay for the tokens the model reads and writes, at the prices per 1M tokens on the models page, in roubles: from the plan's allowance first, then from the balance.

Every request, with its model, tokens and cost, is in the request log of the dashboard.

## If something does not work

-   `401` with `invalid_api_key` or `missing_api_key`: the tool does not send the key, or it is not an active `aictrlx_live_...` key. Create a new one on the API Keys page.
-   `404` with `model_not_found`: the model name is neither a routing mode (`auto`, `fast`, `smart`, `coding`) nor an id from the models page.
-   `403` with `model_not_allowed`: the key is limited to some models; allow this one in the key's settings.
-   `429`: too many requests per minute (`rate_limit_exceeded`), or a quota or budget ran out (`monthly_quota_exceeded` and others).

[All errors and limits →](https://aictrlx.ru/docs#errors)

## Other integrations

-   [Claude Code with aictrlx](https://aictrlx.ru/docs/claude-code)
-   [Cursor with aictrlx](https://aictrlx.ru/docs/cursor)
-   [Continue with aictrlx](https://aictrlx.ru/docs/continue)
-   [LangChain with aictrlx](https://aictrlx.ru/docs/langchain)
-   [LiteLLM with aictrlx](https://aictrlx.ru/docs/litellm)

## Need a key?

Sign up: the key is in the dashboard a minute later.

[Create a free account →](https://aictrlx.ru/register)

## What's new

New models, routing modes and API changes.

[Changelog →](https://aictrlx.ru/docs/changelog)
