# AI

Language models from the back end, over each provider's own HTTP API,
behind one surface: Anthropic's Messages API, OpenAI's Responses API, any
OpenAI-style Chat Completions API, and Google's Gemini API, chosen by a
setting or by the ask. A turn, a stream into the person's page (or out of a
route as server-sent events), tools that are the program's own typed fns,
answers read into a `shape`, images and documents, prompt caching, token
counts, batches, files, pictures and speech; retries, a cache, recorded
replies, costs and per-person budgets; embeddings, chunking, a vector store
in the program's own database, Pinecone, Qdrant and reranking; and `AiChat`,
the kit's chat parts wired to it. An [extension](../extensions/README.md):
ordinary Mote in `extensions/ai/`. Back to the [map](README.md).

```mote
use "pkg:ai/chat.mote"

// The weather in a city now.
fn weatherIn(city: string): string = `18°C in ${city}`

// The program's tools: the model asks by name, the program runs its own fns. The schema is
// the fn's parameters, written by the compiler, and the comment above it is the description.
fn aiChatTools(): AiTool[] = [aiToolFor("weather", schema(weatherIn))]

fn aiTool(name: string, input: json): string
  if name == "weather" return weatherIn(`${input.city}`)
  return fail(`no tool ${name}`)?

column height=520 padding=16
  AiChat
```

```toml
[packages]
ai = "../mote/extensions/ai"
```

```sh
AI_KEY=sk-ant-… bun dist/server/main.js                         # Anthropic, claude-opus-5-5
AI_PROVIDER=responses AI_KEY=sk-… bun dist/server/main.js       # OpenAI, gpt-5
AI_PROVIDER=gemini AI_KEY=… bun dist/server/main.js             # Google, gemini-2.5-flash
AI_PROVIDER=openai AI_API=https://…/v1 AI_MODEL=… AI_KEY=… …    # any Chat Completions service
```

**None of the services has been met.** Every request and every answer is
written from each provider's API reference as of 2026-11 (Anthropic's
version `2026-10-21`; OpenAI's Responses and Chat Completions; Gemini's
`v1beta`; Pinecone's `2025-04`; Qdrant's REST API; Cohere's and Voyage's
v1/v2), and checked only against stand-ins that answer and stream as those
do (`tests/svc_standin.mjs anthropic`, `openai`, `responses`, `gemini`) and
against `given net` in the extension's own tests. Where a field was written
from memory rather than a reference it is said below. The steps to check
each with a real key are [at the end](#checking-it-against-the-services).

## The files

| | |
|---|---|
| `pkg:ai/ai.mote` | The calls and the shapes, every provider's (it takes `anthropic.mote`, `openai.mote`, `gemini.mote`). |
| `pkg:ai/chat.mote` | `AiChat`: a chat in the page, for whoever is signed in. |
| `pkg:ai/retrieval.mote` | Chunks, the vector store, Pinecone, Qdrant, reranking. |
| `pkg:ai/eval.mote` | For `mote test`: answers in each provider's shape, grading, a model as judge. |

The fns read secrets and settings, so they are called from the back end
(`server fn`s, routes, jobs).

## The settings

| | |
|---|---|
| `AI_PROVIDER` | `anthropic` (unsaid), `responses` (OpenAI's Responses API), `openai` (Chat Completions: OpenAI's, or any service that speaks it), `gemini` (the Gemini API); `bedrock` with the aws extension's `pkg:aws/bedrock.mote` ([aws.md](aws.md)), `vertex` with the gcloud extension's `pkg:gcloud/vertex.mote` ([gcloud.md](gcloud.md)): each declares the fn `ai.mote` wants for it (`aiViaBedrock`, `aiViaVertex`). An ask may say its own (`provider:`). |
| `AI_KEY` | The key, read with [`secret(…, "")`](back-end.md#secrets) by `fn aiKey(provider)` (it may be unset: Bedrock and Vertex need none, and a provider asked with no key refuses, kind `auth`). A program that speaks to several providers (a model at one, embeddings at another, Pinecone) declares that fn itself, each its own secret: `fn aiKey(provider: string): string = provider == "pinecone" ? secret("PINECONE_KEY") : secret("ANTHROPIC_KEY")`. One that makes no live call declares it as `""`, and needs no key at all. |
| `AI_MODEL` | The model of AI_PROVIDER's asks. |
| `AI_API`, `AI_API_ANTHROPIC`, `AI_API_OPENAI`, `AI_API_GEMINI`, `AI_API_VOYAGE`, `AI_API_COHERE` | Another address: an OpenAI-style service's own (`https://…/v1`), a stand-in. |
| `AI_FALLBACKS` | `off`: at Anthropic, no server-side fallback when the model declines. Unsaid, `fallbacks: "default"` (beta `server-side-fallback-2026-07-01`). |
| `AI_RETRIES` | How many times a request refused as too many (429) or overloaded (529) is sent again, after what the provider says to wait: 2 unsaid. |
| `AI_CACHE` | Seconds a reply is kept and given again for the very same request. Unsaid, none is kept. |
| `AI_RECORD`, `AI_REPLAY` | A folder of the data folder. Recording, every reply is written there by its request's hash; replaying, replies come only from there and nothing is sent. |
| `AI_BUDGET_TOKENS`, `AI_BUDGET_DOLLARS` | What one person may spend in a day. Unsaid, no limit. |
| `AI_PRICES` | `model=in/out,…`, dollars a million tokens, over the table in `aiPrice`. |
| `AI_EMBED`, `AI_EMBED_MODEL` | Who embeds: `openai`, `gemini`, `voyage`, `cohere`, `local`. |
| `AI_IMAGE_MODEL`, `AI_SPEECH_MODEL`, `AI_TRANSCRIBE_MODEL`, `AI_MODERATION_MODEL` | OpenAI's models for those. |
| `PINECONE_HOST`, `QDRANT_URL`, `AI_RERANK`, `AI_RERANK_MODEL` | [Retrieval](#retrieval). |

### The models, and how to change them

The models used when none is said are in one fn, `aiDefaultModel` at the
top of `extensions/ai/ai.mote`: `claude-opus-5-5` at Anthropic (checked
against Anthropic's model list as of 2026-11), `gpt-5` at OpenAI, and
`gemini-2.5-flash` at Google (the newest this was written knowing of: check
each provider's list). An OpenAI-style service of another (`AI_API` set) has
none, and says so. To change one: set `AI_MODEL`, or say `model:` in an ask,
or change that fn in your copy. The embedding models are `aiEmbedModel`'s
beside it.

## The calls

| | |
|---|---|
| `aiChat(ask)` | One turn: an `AiReply`. |
| `aiStreamTo(ask, to, event)` | The same turn, streamed: each piece of text is `emitTo(to, event, piece)` as it is written (`on piece(text: string)` in that person's page). |
| `aiStreamEach(ask, tell)` | The same, each piece handed to a fn of the program's, `(piece: string) => bool`; `false` stops the stream. |
| `aiRun(ask, turns, to, event)` | Turns until the model is done: each call is checked against its tool's schema and run through `fn aiTool(name, input)`, its result sent back (a failure as one), `turns` times at most; streamed when `to` is not `""`. The reply's usage is all the turns'. `aiRunEach(ask, turns, tell)` streams to a fn. |
| `aiObject(ask, schema)` | An answer in a shape: `let r: Recipe = aiObject(ask, schema(Recipe))?`. Fails `refusal`, `max`, or `invalid` (with the field that is wrong). |
| `aiEventsOut(req, ask, turns)` | A model's answer out of a `server route` as [server-sent events](back-end.md#events-out-of-a-route), for a client that is not one of the program's pages: `delta` for each piece, then `done` with `{text, stop, model, usage}`. |
| `aiCountTokens(ask)` | Tokens, as Anthropic or Gemini counts them; at OpenAI, about (`aiTokensAbout`: a token is four characters), since it has no such call. |
| `aiEmbed(texts, kind)` | Each text as a vector (`kind`: `"query"` or `"document"`). |

`ask` is a record, every field but `messages` optional:

| | |
|---|---|
| `messages` | `AiMessage[]`: `{role, text, parts?, calls?, callId?, failed?, raw?, name?}`. `"user"`, `"assistant"` (with the calls it made, and `raw`, the provider's own content, sent back as it came: Anthropic's thinking blocks, OpenAI's reasoning items, Gemini's thought signatures must be), `"tool"` (a result: `callId`, `name`). |
| `system` | The system prompt. |
| `tools` | `AiTool[]`: `{name, description, schema, strict?}`. |
| `toolChoice` | `"auto"`, `"none"`, `"required"` or a tool's name. Claude Opus 5.5 and Anthropic's other newest models refuse the last two (a 400): steer with the prompt, or ask for a `schema`. |
| `schema`, `schemaName` | The answer is JSON that holds to the schema: Anthropic's `output_config.format`, OpenAI's `json_schema` (strict where the schema allows), Gemini's `responseJsonSchema`. `AiReply.json` is it, read. |
| `effort` | `"low"` … `"max"`: Anthropic's `output_config.effort` (Opus 5.5 is `medium` unsaid), OpenAI's reasoning effort, Gemini's `thinkingLevel` (`low`, `high`). |
| `thinking` | `"summarized"`: a summary of the model's thinking, in `AiReply.thinking`. |
| `cache` | At Anthropic, `"5m"` or `"1h"`: the prompt is kept for the next request (`cache_control` at the top of the request). A part's `cache: true` is a breakpoint of its own. OpenAI and Gemini cache by themselves. |
| `temperature`, `stop`, `maxTokens` | `temperature` is not sent to Anthropic, whose current API refuses it. `maxTokens` is 16000 unsaid at Anthropic, 64000 streamed. |
| `user` | Whose turn: its cost is counted against their [budget](#costs-and-budgets). |
| `provider`, `model` | This ask's own. |

A message's `parts` are `AiPart`s, beside its text: `{kind: "image" |
"document" | "text", data?: bytes, type?, url?, file?, name?, cache?,
cite?}`. `data` is sent as base64 (a `text/…` document as text), `url` for
the provider to fetch, `file` an id `aiFileUpload` gave. `cite: true` asks
Anthropic for citations, which come back in `AiReply.citations` (`{text,
cited, document, title, kind: "char" | "page" | "content_block", start,
end}`).

`AiReply` is `{text, calls, stop, model, usage, message, json?, thinking?,
citations?, provider?, from?}`. `stop` is `"end"`, `"tool"`, `"max"`,
`"refusal"` or `"other"`. `usage` is `{input, output, cacheRead?,
cacheWrite?, cost?}` (input all of it, the cached part among it; cost in
dollars). `from` is `"provider"`, `"cache"` or `"replay"`. `message` is the
assistant message to put in the conversation.

| Kind | |
|---|---|
| `"invalid"`, `"auth"`, `"limited"`, `"overloaded"` (529, 503), `"ai"` (5xx), `"offline"` | The provider's words follow "The model's service refused:"; `err.data` has `status`, `type`, `code`, `retryAfter`. |
| `"budget"` | The person's day is spent. |
| `"replay"` | `AI_REPLAY` has no reply for this request: the words name its hash. |
| `"refusal"`, `"max"` | `aiObject`: the model declined, or ran out of tokens. |

### Tools and answers from the program's own types

`schema(X)` is a shape's fields, or a fn's parameters, as a JSON
Schema, worked out by the compiler and written into the program as a
literal: nothing is read at run time. Every object is `additionalProperties:
false`; a field is `required` unless it is `T?` or `json`; `T?` is `anyOf:
[T, null]`; a shape inside is written out where it stands. The comment above
a shape, its fields and a fn becomes their `description`, so the words the
model reads are the ones the program's reader reads.

```mote
// A dish, as the model is to write it.
shape Recipe
  // What it is called.
  title: string
  minutes: number
  steps: string[]
  note: string?

server fn recipe(words: string): Recipe requires signedIn limit 20 per hour
  let r: Recipe = aiObject({messages: [{role: "user", text: words}]}, schema(Recipe))?
  return r
```

A schema of a fn's type is refused (`H313`), and `schema` of what is no
type (nor a fn's name) is `H318`. `aiRun` checks each tool call's input against its schema
(`aiCheck(schema, value, at)`) before the tool runs: one that does not hold
(a field missing, a number where a text is to be, an input cut short by
eager streaming) goes back to the model as a failure that says which, and
the tool is not called. OpenAI's strict mode wants every field in
`required`: `aiStrict` makes it so (a field that may be left out already
takes `null`), and a schema with a `json` field (`{}`, anything) is sent
not strict, which strict mode would refuse.

### Sending again, keeping, and recordings

- **Retries** are the back end's own [`net.send`](data.md#netsend) with
  `retryOn: [429, 529]`: only an answer that says nothing was done is sent
  again (after `retry-after`, or OpenAI's `retry-after-ms`), and a request
  that got no answer is not, since it may have been done and paid for. A
  5xx is said, not sent again.
- **The cache** (`AI_CACHE=600`) keeps each reply ten minutes by its
  request's hash (provider, address and body): the very same ask is
  answered without asking. `AiCached` is a model of the program's database.
- **Recordings.** `AI_RECORD=recordings` writes each reply to
  `<data>/recordings/<hash>.json`; `AI_REPLAY=recordings` answers only from
  there, and fails `"replay"` for a request it has not seen: tests and
  demos of the real thing, recorded once against the provider.
- **Replies of the program's own.** `fn aiReplay(ask: AiAsk): AiReply?`:
  a reply for an ask, or none to ask the provider. The playground's AI page
  runs on it (and `fn aiKey` saying `""`), so no key is needed and nothing
  is sent.

### Costs and budgets

Every reply's `usage.cost` is what it cost in dollars, as `aiPrice(model)`
prices it: Anthropic's list prices as of 2026-11 (cache reads as Anthropic
prices them, writes a quarter over the input price), `AI_PRICES` over them,
and 0 for a model it does not know (OpenAI's and Google's are not in the
table: say them in `AI_PRICES`). A turn with a `user` is counted in
`AiSpend` (by person and day: calls, tokens in and out, dollars), and
`AI_BUDGET_TOKENS` / `AI_BUDGET_DOLLARS` (or `fn aiBudget(user):
AiBudget`) stop a person when their day is spent: kind `"budget"`, before
anything is sent. `server fn aiMySpend()` is the signed-in person's day,
for a page. A reply from the cache or a recording costs nothing.

## Each provider's own

**Anthropic** (`anthropic.mote`): messages with tools and `tool_choice`,
`strict` tools, images and documents as base64, text, an address or a file,
citations, prompt caching (the whole prompt or a breakpoint), adaptive
thinking shown summarized, effort, structured output, stop sequences,
server-side fallbacks, `count_tokens`; message batches
(`aiAnthropicBatch(items)`, `aiAnthropicBatchGet(id)`,
`aiAnthropicBatchResults(batch)`: each result by its id, in no order;
`fallbacks` is left out, since the Batches API refuses it); files
(`aiFileUpload("anthropic", data, name, type, "")`).

**OpenAI** (`openai.mote`): the Responses API (input items, function calls
and their outputs, reasoning items sent back as they came, instructions,
`text.format`, reasoning effort and summaries, streamed by its
`response.output_text.delta` events and finished by `response.completed`)
and Chat Completions (`response_format`, `reasoning_effort`, images and
files as data addresses); `aiEmbed`; pictures (`aiImage(prompt, size, n)`,
`aiImageEdit(image, prompt, mask)`: PNG bytes, gpt-image-1); speech
(`aiTranscribe(audio, name, type)`, gpt-4o-transcribe; `aiSpeak(text,
voice)`, MP3, gpt-4o-mini-tts); `aiModerate(text)` (`{flagged,
categories}`, omni-moderation-latest); files (`aiFileUpload("openai", …,
purpose)`); batches (`aiOpenAiBatch(items, endpoint)`: a file of requests
kept and the batch begun; `aiOpenAiBatchGet`, `aiOpenAiBatchResults`). The
model names of pictures and speech are those as of what this was written
knowing.

**Gemini** (`gemini.mote`): `generateContent` and
`streamGenerateContent?alt=sse` (each event the parts written since the
last, put together), the key as `x-goog-api-key`, `systemInstruction`,
function declarations with `parametersJsonSchema` and calls answered by a
`functionResponse` of the tool's name, `toolConfig` (`AUTO`, `NONE`,
`ANY`), images and files as `inlineData` and `fileData`, structured output
(`responseJsonSchema`), the model's turns sent back as they came (with their
thought signatures, which Gemini asks for), `countTokens`,
`batchEmbedContents`, and files by the resumable upload
(`aiFileUpload("gemini", …)`: its id is the file's address, kept two days).
Unsure as of writing: `thinkingLevel` is the newest models'; the 2.5 models
take `thinkingBudget`, a number of tokens, which is not sent.

**Left out**, on purpose or for want of a means: OpenAI's Realtime API and
Gemini's Live API (speech both ways over a WebSocket: the back end's
client, [`ws.open`](back-end.md#connections-of-its-own), is there now; what
remains is each session's protocol, audio in and out and its events, in
`openai.mote` and `gemini.mote`); Anthropic's server tools (web search, code execution) and
Managed Agents, which need no client of this kind; OpenAI's Assistants API
(retired in favour of Responses) and fine-tuning; Gemini's explicit context
caches and batch mode; image generation at Google; a tokenizer of any
provider's (counts are asked, or about).

## AiChat

`use "pkg:ai/chat.mote"`: `AiChat` is the kit's `Chat`, `Message`,
`Bubble`, `MessageResponse` and `PromptInput` ([kit/chat.md](kit/chat.md))
over `server fn aiChatSay` (`requires signedIn`, 30 a minute), the reply
streamed into the page as it is written. The program says, each optional:

| | |
|---|---|
| `fn aiChatSystem(): string` | The system prompt. |
| `fn aiChatTools(): AiTool[]` | The tools, run by `fn aiTool`. |
| `fn aiChatMay(): bool` | Who may (everyone signed in, unsaid). |
| `fn aiChatContext(said: string): string` | What the model is to answer from, found for what was said: `aiContext(aiSearch("notes", said, 4)?)`. Put after the system prompt, with the ask to name each document it uses. |

The conversation is the page's state (`aiTurns`), sent with each question;
the system prompt, the tools and the context are the back end's alone. Each
turn is the signed-in person's (`user:`), so it is counted and budgeted.

## Retrieval

`use "pkg:ai/retrieval.mote"`:

| | |
|---|---|
| `aiChunks(text, size, overlap)` | A text in pieces of about `size` tokens, at paragraphs where it can (a longer paragraph at sentences, a longer sentence at words), the last `overlap` tokens of each again at the start of the next. Each `AiChunk` is `{text, from, to, heading, tokens}`. |
| `aiChunksMarkdown(text, size)` | A Markdown text by its headings, read with the [syntax battery](text.md#markdown): each piece the blocks under one heading, packed to about `size`, beginning with the headings it is under (`Setup > Linux`), so that it is understood alone. |
| `aiIndex(store, docs)` | `AiDoc`s (`{id, text, meta}`) embedded 64 at a time and kept in `AiVector`, the program's own model. |
| `aiSearch(store, query, k)` | The `k` nearest what `query` means: `AiHit`s `{id, text, score, meta}`, nearest first. `aiContext(hits)` writes them for a prompt. |
| `aiVectorPut(store, doc, text, vec, meta)`, `aiVectorTop(store, vec, k)`, `aiVectorDel(store, doc)` | The same with vectors of the program's own. |
| `aiPineconeUpsert(namespace, docs, vecs)`, `aiPineconeQuery(namespace, vec, k, filter)`, `aiPineconeDelete` | An index at Pinecone (`PINECONE_HOST`, the index's own address; key `aiKey("pinecone")`). |
| `aiQdrantMake(collection, dims)`, `aiQdrantUpsert`, `aiQdrantSearch(collection, vec, k, filter)`, `aiQdrantDelete` | A collection at Qdrant (`QDRANT_URL`; key `aiKey("qdrant")`, `""` for one of your own). A point's id is a UUID made from the program's id, which is kept in its payload. |
| `aiRerank(query, texts, top)` | The texts in order of how well each answers: Cohere's `rerank-v3.5` or Voyage's `rerank-2.5` (`AI_RERANK`). |

**The store in the database is exact**: every vector of the store is read
and compared with the query (cosine, as the dot product of two vectors of
length 1, by [`bytes`' `dot`](language.md#bytes), over 32-bit floats kept in
a blob). Measured on the machine this was written on (an Apple laptop,
Bun), one search with `k` 10, the database's read included:

| Vectors | 1536 numbers each (OpenAI's small model) | 256 each |
|---|---|---|
| 1,000 | 6 ms | |
| 10,000 | 50 ms | |
| 50,000 | 240 ms | 60 ms |

So it is right to some tens of thousands of vectors for a page that waits
for it, and to a few thousand for one asked many times a second. Past that,
Pinecone or Qdrant, which keep an index. (Each vector is 6 KB at 1536:
50,000 are 300 MB of the database.)

`AI_EMBED=local` is a vector of the text's own words, hashed (256 numbers):
no service and no key, texts that share words found together, meaning not
at all. It is what the tests and the playground use, and a start.

## Testing

`use "pkg:ai/eval.mote"` in a program's tests:

```mote
test "the assistant asks the tool"
  given secret "AI_KEY" is "sk-ant-test"
  given net "https://api.anthropic.com/v1/messages" answers aiCalls("weather", {city: "Oslo"})
  trusted
    let r = aiChat({messages: [{role: "user", text: "Oslo?"}], tools: aiChatTools()})?
    expect aiGrade(r, {calls: ["weather"], stop: "tool"}) == []
```

| | |
|---|---|
| `aiSays(text)`, `aiCalls(name, input)`, `aiStreams(text)` | Anthropic's answer of a text, of a tool's call, and its stream: what `given net … answers` takes. |
| `aiOpenAiSays(text)`, `aiResponsesSays(text)`, `aiGeminiSays(text)` | The same at the others. `aiSse(events)` makes any event stream. |
| `aiGrade(reply, {contains, lacks, calls, stop, schema, most})` | Every way the reply misses, as sentences: `[]` when none. |
| `aiJudge(question, answer, rubric)` | `{pass, why}`, as a model judges: a structured answer, so the verdict is read, not guessed at. Against recordings (`AI_REPLAY`) in tests, live when measuring a change. |

`fn aiReplay(ask)` in a test program, or `AI_REPLAY`, runs a program on
replies given beforehand, with no `given net` at all.

## Checking it against the services

Nothing above has met a real service. With a key of each, in this order:

1. **Anthropic** (`AI_KEY` from platform.claude.com): `aiChat` of one
   question (`model` is `claude-opus-5-5`, `usage` has counts); `aiRun`
   with a tool (the second request carries the first turn's thinking
   blocks as they came); `aiObject` with `schema` of a shape;
   `aiStreamTo` into `AiChat` in a browser; a document part with `cite:
   true` (citations come back); `cache: "5m"` twice (the second's
   `usage.cacheRead` is not 0, given a prompt over the model's minimum);
   `aiCountTokens`; a batch of two (`aiAnthropicBatch`, then
   `aiAnthropicBatchGet` until `ended`, then the results).
2. **OpenAI** (`AI_PROVIDER=responses`, `AI_KEY` from platform.openai.com):
   the same four; then `AI_PROVIDER=openai` for Chat Completions; `aiEmbed`
   with `AI_EMBED=openai`; `aiImage`, `aiTranscribe` of a short recording,
   `aiSpeak`, `aiModerate`; `aiFileUpload` then a document part with its
   `file`; `aiOpenAiBatch` of two. Check `gpt-5` is still the model to use,
   and the picture and speech models.
3. **Gemini** (`AI_PROVIDER=gemini`, a key from Google AI Studio): one
   turn, a tool run (the second request carries the thought signature),
   `aiObject`, a stream, `aiEmbed` with `AI_EMBED=gemini`, `aiFileUpload`
   of a PDF and a part naming it. Check `responseJsonSchema` and
   `parametersJsonSchema` are taken by the model you use (older ones take
   `responseSchema` and `parameters`, an OpenAPI subset), and
   `thinkingLevel`.
4. **Pinecone** (an index of the embedding's dimension, `PINECONE_HOST`),
   **Qdrant** (`docker run -p 6333:6333 qdrant/qdrant`, `QDRANT_URL`,
   `aiQdrantMake` first), **Cohere** or **Voyage** (`aiRerank`): an upsert,
   a query that finds it, a delete.
5. Each with a wrong key: kind `"auth"`, and the provider's words; and the
   log never holds a key (it is a secret).

Recorded in `tests/expect/real_svc_ai.txt` (`tests/all.sh real_svc_ai`):
Anthropic and an OpenAI-style service: one turn, a tool call, a run to the
end, a tool that fails, a streamed run; a refusal; `AiChat` in a browser;
and the extension's own `mote test` (27 tests, every provider's request and
answer). In `tests/expect/real_svc_ai2.txt` (`real_svc_ai2`): the Responses
API and Gemini, a tool from a typed fn, a run with the turn sent back as it
came, an answer in a shape, a 429 waited out, embeddings into the vector
store and the nearest found, and a model's answer read as server-sent
events out of a route. The playground's AI page runs in
`real_pg_playground`.
