> This page is for version v1 (default).
> For other versions, use one of these documentation indexes:
> - v1 (default): https://docs.butterix.com/en/llms.txt
> - v0: https://docs.butterix.com/en/v0/llms.txt

> For the MDX source of any page, append .mdx to the page URL.
> For a complete documentation index, see https://docs.butterix.com/en/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.butterix.com/_mcp/server.
> If something on this page is wrong or missing, POST JSON {"page": "<page URL>", "message": "<what is wrong>"} to https://docs.butterix.com/_biti/feedback/agent.

# Ask AI chat (SSE)

`POST /_biti/ai/chat`

Searches the site's docs and streams an answer with numbered citations. The response is `text/event-stream`, with these events in order:

| Event | Data |
|---|---|
| `sources` | `[{ n, title, heading?, url }]` cited sources |
| `text` | `{ t }` a piece of text (many times) |
| `done` | `{ model, sig?, notice? }` |
| `error` | `{ message, code? }` |

`done.sig` is the server's signature for this turn; send it back with the matching `assistant` message in follow-ups. Turns without a valid signature aren't passed to the model as context.
Questions clearly unrelated to the docs get no generated answer: `text` is a fixed note and `done` is `{ model: null, notice: "offtopic" }`.
When the site reaches its daily limit, only related docs are returned and `done` is `{ model: null, notice: "budget" }`.

Requirements on the hosted platform:

- Requests must come from the site's own pages (`Origin` matches the site and `Sec-Fetch-Site` is `same-origin`); otherwise 403.
- Sites built with a recent version must also send a [session token](https://docs.butterix.com/en/api-reference/runtime/ask-ai-token.md) in the `X-Biti-AI-Token` header. If it's missing or expired you get 401 (`code: "ai_token"`); fetch a new one and retry.

Rate limits: 12 per minute and 200 per day per IP (per /64 for IPv6); 60 per minute and 1000 per day per network (/24 for IPv4, /48 for IPv6); at most 2 answers at a time per IP.
Returns 404 when the site has Ask AI turned off, and 503 when no key is configured or the monthly quota is used up. Because requests must be same-origin, **Try it** on API reference pages can't call this endpoint.

Base URL: https://butterix-sites.butterix.com

## Header parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `X-Biti-AI-Token` | string | no | Session token (required for sites built with a recent version on the hosted platform) |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `messages` | list of objects | yes | Conversation history; the last message must be from `user` |
| `messages[].role` | enum | yes | Allowed: `user`, `assistant`. |
| `messages[].content` | string | yes | `user` messages can have up to 512 characters |
| `messages[].sig` | string | no | For `assistant` messages: the signature returned by that turn's `done` event |
| `locale` | string | no | Answer language; the site's first language by default |

## Example request

```bash
curl -X POST https://butterix-sites.butterix.com/_biti/ai/chat \
     -H "Content-Type: application/json" \
     -d '{
         "messages": [
           {
             "role": "user",
             "content": "How do I add an English version of my site?"
           }
         ],
         "locale": "zh"
       }'
```

## Responses

### 200

Event stream

Content type: `text/event-stream` (stream; each event has these fields)

Type: string

### 400

The last message isn't a question, or the question is longer than 512 characters (`code: "too_long"`)

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | Human-readable error message |
| `code` | string | no | Machine-readable error code (some endpoints) |

### 401

Session token missing or expired (`code: "ai_token"`)

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | Human-readable error message |
| `code` | string | no | Machine-readable error code (some endpoints) |

### 403

The request doesn't come from the site's own pages (`code: "origin"`)

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | Human-readable error message |
| `code` | string | no | Machine-readable error code (some endpoints) |

### 413

Request body larger than 256 KB (`code: "too_large"`)

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | Human-readable error message |
| `code` | string | no | Machine-readable error code (some endpoints) |

### 429

Too many questions (`code: "rate_limited"`) or too many answers at once (`code: "busy"`)

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | Human-readable error message |
| `code` | string | no | Machine-readable error code (some endpoints) |

### 503

No AI provider configured

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | Human-readable error message |
| `code` | string | no | Machine-readable error code (some endpoints) |

### Example response (200)

```json
"event: sources\ndata: [{\"n\":1,\"title\":\"Internationalization\",\"url\":\"/guides/features/i18n\"}]\n\nevent: text\ndata: {\"t\":\"Add en to languages in docs.yml [1], \"}\n\nevent: text\ndata: {\"t\":\"then put the translations under translations/en/.\"}\n\nevent: done\ndata: {\"model\":\"claude-opus-5-5\",\"unanswered\":true}\n"
```
