Docs chatbot (POST /docs/v1/chat)
A public, unauthenticated endpoint that answers questions about the AI Gateway product from the official documentation, grounded in the docs corpus with inline citations. It backs both the in-app "Ask the docs" panel and the public documentation-site widget. No token or session is required.
The endpoint is a dedicated front door: it can only reach the documentation assistant. It cannot be used for general-purpose inference, and it cannot reach any tenant, gateway, or agent other than the documentation one — the target is pinned server-side, so nothing in the request selects it.
Request
POST /docs/v1/chat · Content-Type: application/json · no Authorization
messages— required, a non-empty array of turns (the client keeps the short conversation history and resends it each call).- each turn:
{ "role": "user" | "assistant", "content": "<string>" }. rolemust be exactlyuserorassistant;system/developerturns are rejected (the assistant's grounding instructions cannot be overridden by the caller).contentmust be a string.
- each turn:
stream— optional boolean.truestreams the answer token-by-token as Server-Sent Events (Content-Type: text/event-stream): OpenAI-styledata: {chat.completion.chunk}frames whosechoices[0].delta.contentcarries each token, adata: [DONE]terminator, and: hbheartbeat comments to ignore. Absent/falsereturns one buffered JSON completion. To stop mid-stream, the client closes the connection (e.g.AbortController) — the server honours the abort.
x-aig-extensions and the other x-aig-* control headers are ignored on this endpoint.
CORS is open (Access-Control-Allow-Origin: *); the endpoint reads no cookie and carries no
credentials, so it may be called from any web origin (e.g. an embedded docs-site widget).
What is rejected (HTTP 400)
The body is validated at the trust boundary and fails closed — an absent and a malformed value are both rejected, never defaulted through:
- a missing/empty body, or a body that is not a JSON object;
- a body that repeats a key at any depth (
400 duplicate_key), holds a non-finite number such as1e400(400 invalid_request), or has more than 2,048 structural elements (body_too_complex, HTTP 413); messagesabsent, not an array, or empty;- a message that is not an object, whose
roleis notuser/assistant, or whosecontentis not a string (a missingcontent, a number, or an object all reject); - a request with no
userturn; - more than 20 turns, a single message over 8 000 bytes, or a conversation over 24 000 bytes total.
Response
200 OK with an OpenAI-compatible completion (or an SSE stream when stream:true); the answer text
carries inline [file | page | section] citations to the documentation — clients may turn these into
links to the live docs page. If the docs do not cover the question, the assistant says so rather than
guessing.
How the assistant searches (search before answering)
Before the model writes its first word, the gateway searches the documentation once for your latest message and hands the passages to the model, so the first answer is already grounded and starts sooner. When those passages cover your question, the assistant answers directly from them. The assistant may search at most one more time (one call, several phrasings in its query) when those passages do not cover the question. If that bound is reached, it answers from the documentation it has already found and nothing else — it does not fall back to general knowledge. Such an answer carries no stop note. Only when no answer could be produced at all does the reply end with one of these sentences (the language follows your question):
- English: "I could not finish an answer from the documentation. Please rephrase your question."
- German: "Ich konnte aus der Dokumentation keine vollständige Antwort erstellen. Bitte formulieren Sie Ihre Frage um."
German answers address you formally ("Sie", "Ihnen", "Ihr"), including short follow-up questions in a German conversation. This is lane policy: German answers always use "Sie", also when the visitor asks to be addressed with "du".
If the documentation search itself fails, the request fails with an INTERNAL error ("failed to prepare the docs
search results") instead of an answer that is not grounded.
Client rendering (how the answer is displayed)
The answer content is Markdown. The in-app panel and the public docs-site widget both render a
safe Markdown subset — headings, paragraphs, bold/italic, inline and fenced code, ordered/unordered
lists, links, and soft line breaks. The model answer is treated as untrusted at the render boundary:
- it is turned into DOM nodes (never injected as HTML), so any
<tag>or<script>in the answer shows as literal text and can never execute; - link targets are scheme-checked —
http(s),mailto:, and relative/anchor links render as links (external ones open in a new tab,rel="noopener noreferrer"); any other scheme (javascript:,data:,vbscript:, protocol-relative//host, or control-char-obfuscated variants) renders as inert text, never a clickable link; - anything outside the subset (tables, images, raw HTML) falls back to plain text.
A custom client should apply the same policy; do not render the answer as raw HTML.
Client streaming (how the answer arrives)
Both clients request stream: true and show the answer while it is generated: the panel shows
"Searching the docs…" until the first token, then the answer grows in place. A client reading the stream
should treat it as untrusted, too:
- split frames on newlines across chunk boundaries (a frame can be cut at any byte, also inside a
multi-byte character), accept
\nand\r\n, and read onlydata:lines — skip: hbheartbeats and any other SSE field; - take only a non-empty string
choices[0].delta.content; skip frames that are not JSON or carry anything else, without failing the answer; - stop at
data: [DONE]; if the body ends without it, keep what arrived; - bound what you buffer — the widget caps the answer at 100 000 characters and rejects a stream whose line grows past 400 000 characters without a newline;
-
accept a plain JSON completion as well (a proxy may answer without streaming), and reject any other
Content-Type. -
a frame with an
errorobject ends the answer. Read only itscode(a string of at most 64 characters) and show your own fixed text — never the frame's message.
If the stream breaks after part of the answer arrived, the widget keeps that part, shows an error line under it, and keeps it as context for the next question.
Feedback
POST /docs/v1/feedback — also public, anonymous, credential-less (CORS *). Records a thumbs rating on
an answer:
rating— required, the number1(helpful) or-1(not helpful). A string/boolean/absent value is rejected (400) — fail-closed.question/answer— optional strings. A JSONnullcounts as absent; a non-string is rejected (400). A value that is not valid UTF-8 is rejected (400). A longer value is truncated, not rejected, on a character boundary:questionto 2 000 characters,answerto 8 000 characters.
Returns 204 on success, 400 invalid_request on an invalid body (400 duplicate_key for a repeated key, a non-finite number is a plain 400 invalid_request, 413 body_too_complex above 2,048 structural elements), 405 for a method other than POST,
413 payload_too_large for a body over 64 KB (max_body: 65536), 429 rate_limited when the per-IP cap
(30 requests / 60 s) or the global cap (60 requests / 60 s per node) is exceeded (checked before the body
is read), and also when the cluster-wide storage budget for feedback is used up (60 ratings per minute and 1 000 per day across all callers; the rating is then not stored; a per-minute refusal clears within 60 s, a per-day refusal clears only as ratings older than 24 h leave the rolling window, and no Retry-After is sent), and 503 service_unavailable when the rating cannot be stored or the request body could not be read (retry). The IP is recorded only as a
coarse bucket (IPv4 /24, IPv6 /48, never a raw address); the timestamp is server-set. Ratings are stored anonymously for 30 days and used only in aggregate to improve the docs assistant.
Rate limits & errors
| Status | Meaning |
|---|---|
429 |
rate_limited — a per-IP cap (15 requests / 60 s, checked before the body is validated; IPv6: per /64 — see How the public rate limits behave) and the rate limit configured on the docs gateway protect the shared assistant. The gateway limit sends Retry-After; the per-IP cap does not, so wait for the 60 s window. |
400 |
invalid_request — the request body was invalid (see above); the error message names the failed rule. A repeated key is answered duplicate_key instead. |
413 |
payload_too_large — the request body is over 64 KB (max_body: 65536); refused before it is processed, with the same Access-Control-Allow-Origin: * (see Request body size limits). |
413 |
body_too_complex — more than 2,048 structural elements in the body. |
503 |
ask_docs_unconfigured — the documentation assistant is not provisioned in this environment. Retry later. |
503 |
assistant_unavailable — the assistant cannot answer right now. The body is always the fixed message "The assistant is currently unavailable. Please try again later.": it carries no budget, balance or plan detail, and no Retry-After header. A mid-stream failure arrives as the same data: {"error":{"code":"assistant_unavailable",...}} frame. Retry later. |
On this endpoint a 5xx answer never carries a detail field: the body holds only the code and its fixed message, so no provider, billing or internal text reaches an anonymous caller.
The endpoint runs the same billing, logging, and safety pipeline as authenticated inference; every call is recorded. The assistant uses only the documentation search: it has no web search, file fetch, code execution, or external-tool access, and it never creates or changes files (a question such as "how do I get an Excel export?" is answered from the documentation, nothing is generated or stored).