---
title: "AI API: connecting and requests"
url: https://lumean.app/en/developers/docs/guide/ai-api
locale: en
description: "How to connect to Lumean language and image models over the OpenAI and Anthropic protocols. Base URL, key, endpoints, streaming, limits and errors."
updated: 2026-12-01
sources: [get-ai-models, get-ai-models-key]
spec_version: 1.0.0
---

# AI API: connecting and requests

The AI API is an entry point to language and image models, separate from orders. It speaks the
OpenAI and Anthropic protocols, so any client that works with OpenAI or Anthropic will do: SDKs,
curl, Cursor, Claude Code, Codex CLI, opencode. You don't change the client code, only the base URL
and the key.

Image generation is covered in [AI API: images](/developers/docs/guide/ai-images). Prices and
spending are covered in [AI API: prices and spending](/developers/docs/guide/ai-pricing).

## Base URL

| Client | Base URL |
| --- | --- |
| OpenAI SDK, curl, Cursor, Codex CLI, opencode, Continue, Cline | `https://api.lumean.app/v1` |
| Anthropic SDK, Claude Code | `https://api.lumean.app` (no `/v1`) |

The Anthropic SDK and Claude Code append `/v1/messages` themselves. If you give them a URL with
`/v1`, the path is doubled and the request gets `404`.

The AI API doesn't live under `/api/public` like orders do. It lives directly under `/v1`.

## Key

Any API key from [My API keys](/developers) works, the same one you use for orders. The key's
permissions (`orders.read` and others) aren't checked here. The only requirement is that the "AI"
checkbox is on in the key settings. It's on for a new key. With the checkbox off, the request gets
`401` `not_a_gateway_key`.

Send the key in one of these headers:

```bash
Authorization: Bearer <key>
x-api-key: <key>
```

OpenAI clients send `Authorization` themselves, Anthropic clients send `x-api-key`.

In the key settings you can set a monthly AI spending limit. The calendar month is counted in UTC.
When spending reaches the limit, requests get `402` `key_budget_exceeded` until the next month
starts.

## Payment

The AI API is paid only from the LUMC balance, at the model's price per token or per call.
Subscription tokens and quotas aren't spent here. If the balance runs short, the request gets `402`
`insufficient_quota`. More in [AI API: prices and spending](/developers/docs/guide/ai-pricing).

## Models

Pass the model name in the `model` field, for example `gpt-image-2.5-sunburst` or
`claude-opus-5-5`. The catalog with prices and descriptions is on the [Models](/models) page.

From code, you can get the model list in two ways:

- `GET /v1/models` is a list in the OpenAI shape: name, kind (`chat` or `image`), context size and
  the response ceiling. It has no prices.
- `GET /api/public/ai/models` is the same list with current prices and model capabilities. It's
  described in the reference below.

### GET /ai/models

Current AI model prices

Справочник: https://lumean.app/en/developers/docs/api/get-ai-models

## Endpoints

| Method and path | What it does |
| --- | --- |
| `POST /v1/chat/completions` | OpenAI-format chat. Supports streaming, tools (function calling), `response_format` and image input |
| `POST /v1/responses` | OpenAI Responses format, used by Codex CLI |
| `POST /v1/messages` | Anthropic Messages format, used by Claude Code and the Anthropic SDK |
| `POST /v1/messages/count_tokens` | Estimates the number of input tokens. Free |
| `GET /v1/models`, `GET /v1/models/{id}` | The model list, or one model |
| `POST /v1/images/generations` | An image from a description |
| `POST /v1/images/edits` | An image from a description and reference images |

Every response carries an `X-Request-Id` header. If you write to support about a specific request,
include it.

## First request

```bash
curl https://api.lumean.app/v1/chat/completions \
  -H "Authorization: Bearer $LUMEAN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "messages": [{"role": "user", "content": "Hi! Tell me a joke."}]
  }'
```

The response is in the OpenAI shape, and token usage is in the `usage` field:

```json
{
  "id": "chatcmpl-…",
  "object": "chat.completion",
  "model": "gpt-5.4",
  "choices": [{
    "index": 0,
    "message": {"role": "assistant", "content": "…"},
    "finish_reason": "stop"
  }],
  "usage": {"prompt_tokens": 14, "completion_tokens": 52, "total_tokens": 66}
}
```

The model name in the example is for illustration. Use a model from the catalog.

## Connecting apps and SDKs

Ready-made settings with your key are in your dashboard, in the
[AI connection](/developers/ai-connect) section, and on each model's page. The same settings in
general form:

**OpenAI SDK (Python)**

```python
from openai import OpenAI

client = OpenAI(base_url="https://api.lumean.app/v1", api_key="LUMEAN_API_KEY")

reply = client.chat.completions.create(
    model="<model>",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(reply.choices[0].message.content)
```

**OpenAI SDK (JavaScript)**

```javascript
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.lumean.app/v1", apiKey: "LUMEAN_API_KEY" });
```

**Anthropic SDK (Python)**: the URL has no `/v1`:

```python
from anthropic import Anthropic

client = Anthropic(base_url="https://api.lumean.app", api_key="LUMEAN_API_KEY")
```

**Claude Code**: environment variables, the URL has no `/v1`:

```bash
export ANTHROPIC_BASE_URL=https://api.lumean.app
export ANTHROPIC_AUTH_TOKEN=<key>
export ANTHROPIC_MODEL=<model>
export ANTHROPIC_SMALL_FAST_MODEL=<model>
```

**Codex CLI**: the `~/.codex/config.toml` file:

```toml
model = "<model>"
model_provider = "lumean"

[model_providers.lumean]
name = "Lumean"
base_url = "https://api.lumean.app/v1"
env_key = "LUMEAN_API_KEY"
wire_api = "responses"
```

**opencode**: the `opencode.json` file:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "lumean": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Lumean",
      "options": { "baseURL": "https://api.lumean.app/v1", "apiKey": "{env:LUMEAN_API_KEY}" },
      "models": { "<model>": { "name": "<name>" } }
    }
  }
}
```

**Cursor**: Settings → Models. Paste the key into the OpenAI API Key field, turn on Override OpenAI
Base URL and enter `https://api.lumean.app/v1`, then add the model name.

**Continue**: the `config.yaml` file:

```yaml
models:
  - name: Lumean
    provider: openai
    model: <model>
    apiBase: https://api.lumean.app/v1
    apiKey: <key>
```

**Cline and Roo Code**: use the "OpenAI Compatible" provider. Set Base URL to
`https://api.lumean.app/v1`, then enter the key and the model name.

## Streaming and long responses

With `stream: true` the response arrives in parts (SSE), as with OpenAI and Anthropic. An
OpenAI-format stream ends with the line `data: [DONE]`.

If the model hasn't started responding within 20 seconds, the stream still opens: you get `200`,
and then a `: ping` line every 15 seconds until the response appears. This is a service SSE comment.
Standard SDKs and `EventSource` skip it, and a hand-written stream parser must skip lines that
start with `:`.

An error after the stream has opened arrives as an event in the stream itself, without
`data: [DONE]`. The SDK will throw an exception, but it won't retry the request on its own.

> [!WARNING]
> Without streaming, the full response arrives only after the model finishes. If generation takes
> longer than two minutes, an intermediate proxy on the `api.lumean.net` mirror may drop the
> connection. Turn on `stream: true` for long responses.

## Reasoning effort

The client sets how much the model reasons before answering, in the request body. The AI API passes
this field to the provider unchanged.

| Format | Field | Values |
| --- | --- | --- |
| `POST /v1/messages` | `"output_config": {"effort": "low"}` | `low`, `medium`, `high`, `xhigh`, `max` |
| `POST /v1/responses` | `"reasoning": {"effort": "low"}` | per the model's documentation |
| `POST /v1/chat/completions` | `"reasoning_effort": "low"` | per the model's documentation |

Reasoning is paid as output tokens, so a high level costs noticeably more. For Claude models,
`/v1/messages` is more reliable: in `/v1/chat/completions` the field may get lost when the request
is translated to the provider's format.

## What's not supported

- The provider's built-in tools that it bills separately: web search, page fetching, code
  execution, `mcp_servers`. In `/v1/responses` and `/v1/messages` such a request gets `400`
  `unsupported_tool`. Regular tools (function
  calling) and the agents' client-side tools (`bash`, `text_editor`, `computer`, `apply_patch` and
  similar) work.
- Response storage in `/v1/responses`: responses aren't saved, so `previous_response_id`,
  `conversation` and `background: true` get `400` `unsupported_parameter`. Pass the whole
  conversation in `input`.
- Expensive service modes: in `/v1/responses` and `/v1/messages` `service_tier` accepts only
  `auto`, `default`, `flex` and `standard_only`.
- `n` greater than 1 for images.
- If a model doesn't work in the chosen format, the request gets `404` `endpoint_not_supported`.
  Use `/v1/chat/completions` then.

## Limits

| Limit | Value | Response |
| --- | --- | --- |
| Requests per minute for one key | 300 | `429` `rate_limit_exceeded` and a `Retry-After` header |
| Concurrent requests for one key | limited | `429` `concurrent_requests_limit_exceeded` and a `Retry-After` header |
| Request body size | 32 MiB | `413` `request_too_large` |
| Model response without streaming | the response must start within 300 seconds | `502` `upstream_timeout` |

## Errors

Errors come in the OpenAI shape:

```json
{
  "error": {
    "message": "No API key provided. Send it as `Authorization: Bearer <key>` or `X-API-KEY: <key>`.",
    "type": "authentication_error",
    "param": null,
    "code": "missing_api_key"
  }
}
```

On `/v1/messages` they come in the Anthropic shape: `{"type": "error", "error": {"type": "…", "message": "…"}}`.

| Code | `code` | Cause | What to do |
| --- | --- | --- | --- |
| `401` | `missing_api_key` | No key in the request | Send the key in `Authorization: Bearer` or `x-api-key` |
| `401` | `unknown_key`, `key_inactive`, `key_expired` | The key isn't found, is off or has expired | Check the key in [My API keys](/developers) |
| `401` | `not_a_gateway_key` | The "AI" checkbox is off for the key | Turn it on in the key settings |
| `402` | `insufficient_quota` | Not enough LUMC on the balance | Top up the balance |
| `402` | `key_budget_exceeded` | The key used up its monthly limit | Raise the key's limit or wait for the next month |
| `400` | `invalid_request_body`, `missing_required_parameter` | The request body is invalid or lacks a required field | Fix the request using the `message` text |
| `400` | `unsupported_parameter`, `unsupported_tool` | The parameter or tool isn't supported | See the "What's not supported" section |
| `400` | `context_length_exceeded` | The conversation doesn't fit the model's context | Shorten the conversation or pick a model with a bigger context |
| `404` | `model_not_found`, `model_disabled` | The model doesn't exist or is temporarily off | Pick another model from the catalog |
| `404` | `endpoint_not_supported` | The model doesn't work in this format | Use `/v1/chat/completions` |
| `413` | `request_too_large` | The body is larger than 32 MiB | Reduce the attachments |
| `429` | `rate_limit_exceeded`, `concurrent_requests_limit_exceeded` | The key's limit is exceeded | Wait `Retry-After` seconds |
| `429` | `provider_keys_cooling` | The model's provider has a temporary cap | Retry later or pick another model |
| `502` | `upstream_timeout`, `upstream_error` | The model's provider didn't respond or returned an error | Retry the request |
| `503` | `gateway_at_capacity`, `catalog_unavailable`, `quota_check_unavailable` | Temporary overload | Retry in a few seconds |

Errors that occur only with images are listed in
[AI API: images](/developers/docs/guide/ai-images).

---

- This page in the browser: https://lumean.app/en/developers/docs/guide/ai-api
- Full machine-readable reference: https://api.lumean.app/docs/llm.md
