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

Integration

# LangChain with aictrlx

LangChain's `ChatOpenAI` works with aictrlx when `base_url` points at its API: chains and agents in Python on any model of the catalog, with tool calling and structured output.

## 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_..."
```

Install

```
pip install langchain-openai
```

Python

```
import os

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="auto",
    base_url="https://aictrlx.ru/v1",
    api_key=os.environ["AICTRLX_API_KEY"],
)
reply = llm.invoke("Explain vector databases in two sentences.")
print(reply.content)
print(reply.response_metadata.get("model_name"))  # the model that actually answered
```

## Which model to use

-   `auto` lets aictrlx pick a model for each request by its kind (code, reasoning, a short answer).
-   For tool calling and JSON output, choose a model that supports them on 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)
-   [Vercel AI SDK with aictrlx](https://aictrlx.ru/docs/vercel-ai-sdk)
-   [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)
