AI providers¶
TL;DR
- Every route under
/aiis for a signed-in operator (roleadmin): anyone else gets 403forbidden, an API token 401. - Provider profiles come from the environment or TOML file (read-only) or from this API; stored keys are sealed and never returned.
/ai/rolesshows theembedding,reranker,llmandjudgeroles and sets the thinking level ofllmandjudge./ai/embeddingand/ai/embedding/estimateshow embedding progress and cost;/ai/usageand/ai/usage/historyshow spend and budgets.
They show and change instance-wide settings: provider URLs and keys, spend and budgets of every library. See AI retrieval decisions for the kinds and what each needs.
Endpoints¶
All need an operator session, like /users. Library roles do not count.
| Method | Path | Purpose |
|---|---|---|
GET |
/ai/providers |
list provider profiles |
POST |
/ai/providers |
create a profile |
GET |
/ai/providers/{name} |
one profile |
PUT |
/ai/providers/{name} |
create or replace a profile |
DELETE |
/ai/providers/{name} |
delete a profile |
POST |
/ai/providers/{name}/check |
test the profile with minimal calls |
GET |
/ai/roles |
the instance roles |
PUT |
/ai/roles/{role} |
set a role's thinking level |
GET |
/ai/embedding/estimate |
what embedding the rest would cost |
GET |
/ai/embedding |
the embedding model and its spaces |
GET |
/ai/usage |
spend and budgets now |
GET |
/ai/usage/history |
spend per day or month |
Provider profiles¶
GET /ai/providers¶
Every profile: the environment's and the TOML file's first (origin: configuration,
read_only: true), then those stored here (origin: api).
- Never a key or a header value.
keysays where the key comes from:none,sealed,file,environment.header_nameslists the headers.roleslists the instance roles that use the profile.unsupportedsays what this installation lacks to call it.
Creating and replacing¶
POST /ai/providers(201) with{"name": "gw", "kind": "openai-compatible", "base_url": ..., "api_key": ...}creates one (409provider_exists).PUT /ai/providers/{name}creates or replaces one (nonamein the body).- A change counts at the next call, without a restart.
Keys:
- The key is sealed with the instance's secret key and never returned.
- Without
api_keythe stored key is kept;keep_key: falseremoves it. - If the endpoint changed (kind, platform,
base_url,resource,project,location,proxy), 422invalid_providerasks for the key again, so a stored key never follows a profile elsewhere.
| Error | When |
|---|---|
409 provider_read_only |
a configured name |
422 invalid_provider |
with the field at fault |
422 provider_unsupported |
this installation cannot call the kind (the [ai] extra, boto3 for Bedrock) |
422 secret_key_required |
a key when the process has no secret key |
Refused here, with 422 invalid_provider
- The server's own cloud identity (
credentials: "adc",credentials_file,auth: "entra", Claude on Bedrock). It is configured in the environment or the TOML file only, without abase_url. - Extra
headersthat carry a credential (Authorization,Cookie,x-api-key,api-key,*-key,*-token,*-secret,*-password). The key goes inapi_key. - A
resource,locationorprojectthat is not one DNS label. They become part of the endpoint's host or path.
Reading and deleting¶
GET /ai/providers/{name}reads one.DELETE /ai/providers/{name}answers 204.- 409
provider_in_usewhile an instance role uses it. - A library override naming it stops counting until it exists again.
- 409
Checking a profile¶
POST /ai/providers/{name}/check, optionally with {"role": "embedding", "model": "e5"}, makes
one minimal call per instance role that uses the profile, or to the model named.
Each call is reported as:
{"role", "profile", "model", "status": "ok" | "error", "latency_ms", "served_model",
"dimensions", "error"}
- A failed call is a check with
status: error(its text never holds a key), not a failed request. - 422
nothing_to_checkwhen no role uses the profile and no model is named.
Roles¶
GET /ai/roles¶
The instance roles (embedding, reranker, llm, judge), each with:
- its
model(<profile>:<model>) - its
source:instance, orllmfor a judge that defaults to the LLM - whether its profile exists
The llm and judge roles also have:
| Field | Meaning |
|---|---|
thinking |
the level their calls send; a judge that is the LLM thinks as the LLM |
own_thinking |
set for the role itself |
thinking_configured |
set in the environment or the TOML file, so read-only here |
thinking_unsupported |
why its model cannot take the level, which its calls then leave out |
See Thinking level.
PUT /ai/roles/{role}¶
{"thinking": "low"} (null clears it) sets the thinking level of the llm or judge role, used
from the next call. It answers the role as GET /ai/roles shows it.
| Error | When |
|---|---|
409 role_configured |
EXACTDOCS_AI__<ROLE>__THINKING sets it |
422 role_takes_no_thinking |
embedding and reranker |
422 thinking_unsupported |
the role's model is known to take no thinking setting (naming the role and the model) |
Embedding¶
GET /ai/embedding/estimate¶
What embedding every version not embedded yet would send and cost, before it runs
(exactdocs ai estimate over REST):
{"model", "space_id", "versions", "chunks", "characters", "estimated_tokens",
"usd_per_million_tokens", "estimated_usd", "note"}
characterscounts each chunk's text, heading path and article title, as embedded.- Only active versions of libraries with AI on count, and each stored chunk once (a blob held by many versions is embedded once).
- Tokens are 4 characters each and the price is the bundled price list's (
nullfor a model it does not know): an estimate, asnotesays. - No model or tokenizer is called.
modelisnulland the counts 0 when no embedding model is configured.- 400
vector_store_unavailableon an instance without a vector store. - On PostgreSQL the estimate counts from the stored chunks, with or without pgvector's extension.
GET /ai/embedding¶
The configured embedding model and how far each embedding space has got:
{"model", "spaces": [{"id", "profile_kind", "model", "dimensions", "state", "current",
"created_at", "activated_at", "versions", "versions_embedded", "chunks", "chunks_embedded"}]}
- One entry per space that is not retired, oldest first.
currentmarks the configured model's. While it isbuilding, the olderactiveone answers searches.versionscounts the active versions of libraries with AI on, andversions_embeddedthose it has a vector for every chunk of.chunksandchunks_embeddedcount per version, so a chunk two versions share counts twice.spacesis empty without a vector store or before anything was embedded.
Spend¶
GET /ai/usage¶
What AI calls spent and what is left of each budget ([ai.budgets]):
{"at", "llm_searches_per_minute", "scopes": [{"scope", "id", "day", "month", "budgets"}]}
scope |
id |
|---|---|
instance |
|
embedding (embedding runs, instance-wide) |
|
library |
the library ID |
user |
the account ID |
The instance and embedding come first, then every library and account that spent something this month.
day and month are the current UTC windows:
{"input_tokens", "output_tokens", "tokens", "local_tokens", "requests", "usd",
"unpriced_requests"}
- As the providers reported. An LLM step's tokens, which the harness does not split, are input tokens.
local_tokensare those of in-process (local) models, included in the input and output tokens.tokens, what token budgets count, leaves them out.
Each budget:
{"window", "window_start", "resets_at", "usd_limit", "usd_left", "tokens_limit",
"tokens_left", "reached", "own_usd_limit", "own_tokens_limit"}
nullfor a ceiling that is not set.- A library with budgets of its own shows the tighter of its own and the instance's per-library
ones, with
usd_leftandtokens_leftagainst it. - Where the instance's is lower (it was lowered after the library set its own),
own_usd_limit/own_tokens_limitgive the library's own ceiling. Otherwise they arenull.
GET /ai/usage/history?scope=&id=&window=&from=&to=¶
What one scope spent per UTC day or month, for charts:
{"scope", "id", "window", "first", "last", "entries": [{"window_start", "input_tokens",
"output_tokens", "tokens", "local_tokens", "requests", "usd", "unpriced_requests"}]}
One entry per window from first to last (both included, oldest first), counted as in
GET /ai/usage and zero for a window with no spend.
| Parameter | Meaning |
|---|---|
scope, id |
as GET /ai/usage names a scope: instance (the default) and embedding take no id;library needs the library ID, user the account ID |
window |
day (the default) or month |
from, to |
UTC dates (YYYY-MM-DD); for months any day of a month stands for it |
- A library ID is accepted in any letter case;
idcomes back case-folded, as the ledger keeps it. first/lastare the windows' first days.- Without
tothe range ends with today's window. Withoutfromit holds 30 days or 12 months up toto. - A range ends after it starts and holds at most 366 days or 60 months. Otherwise, or for an
idthat does not fit thescope, it is 422invalid_spend_history. - Dates in the future are allowed (zero).
- Libraries and accounts that no longer exist keep their rows, so their history is still shown.