Endpoint
Prefer POST /v1/chat/completions for new integrations. It supports multi-turn conversations, model override, temperature, and usage tracking via the standard OpenAI wire format.
Request parameters
The API key decides which assistant, and this field has to agree with it.
A key created for one assistant answers for that one whether or not you send
assistant_id; a key scoped to the knowledge base answers from the documents
that belong to no assistant, and rejects a request naming any assistant with
403. Omitting the field is the normal case. See
Authentication.string
The assistant (project) ID to query. Optional — the API key already carries a scope, and this field must agree with it. Find an ID in the dashboard URL when viewing a project (
…/projects/<assistant_id>), via GET /v1/assistants, or under Organization → Assistant settings.string
required
The user’s message. Must be between 1 and 10,000 characters.
string
Additional page or document context passed directly to the model alongside the retrieved chunks. Maximum 20,000 characters. Useful when building embedded chatbots — pass the current page’s content here so the model can answer questions about it even if it isn’t in the knowledge base.
boolean
default:"false"
When
true, the response is returned as a Server-Sent Events stream instead of a single JSON object.string
OpenAI-style reasoning effort:
"low", "medium", or "high". Forwarded to the underlying model; only honored by reasoning-capable models (e.g. GPT-o series). When set, streaming responses additionally emit {"reasoning": "..."} events with the model’s intermediate thinking.boolean
default:"false"
When
true, the response also lists the documents the answer was drawn from. See Sources. Off by default, so the response is unchanged unless you ask.Response
Non-streaming (default)
A JSON object with a singletext field:
string
The AI-generated answer grounded in your knowledge base.
Streaming (stream: true)
Returns a text/event-stream response. Up to three event shapes may appear (the third only when you ask for sources), followed by a [DONE] sentinel:
The stream always ends with
data: [DONE]. Display reasoning chunks separately from the answer or ignore them — most users don’t need to show them.
Sources
Setsources: true to get back the documents the answer was drawn from — the files retrieval put in front of the model, most relevant first. Use it to show a reader where an answer came from, or to link to the original documents.
string
The file’s ID.
string | null
The file’s name, or
null for documents ingested before names were stored.integer
1 is the most relevant.object
Present only when the file is a published Ragen Brain page.
pageTitle is the page’s title, and sources lists the documents the page was built from, with span locating the passage in each. Only documents the API key is allowed to read are listed: a key that can read a page but not all of its documents gets the page and a shorter list, never the names of documents it cannot open.{"sources": [...]} event just before [DONE], so it reflects the finished answer:
"sources": []. Documents outside your key’s scope never appear, because retrieval itself only reads what the key may read.
Examples
- TypeScript SDK
- curl
- TypeScript (fetch)
Use the official
@webamigos/ragen-sdk-ts package for typed responses, streaming iterators, and automatic retries.Error codes
Example error body:
Rate limits
When rate-limited, use exponential backoff with jitter. Each streaming and non-streaming request counts equally against this budget.
How the endpoint works
When you callPOST /v1/chat, Ragen runs a five-step pipeline:
1
Authentication
Your API key is validated and the organization is resolved from it.
2
Assistant resolution
The assistant comes from the API key’s scope. A key bound to one assistant resolves to it; a knowledge-base key resolves to no assistant, and retrieval runs against the documents that belong to none. An
assistant_id in the request must agree with that, or the call is refused with 403.3
RAG retrieval
Relevant document chunks are retrieved from the assistant’s knowledge base with hybrid search (dense vectors plus BM25).
4
Reranking (when enabled)
If the deployment has reranking enabled, retrieved chunks are re-scored before being included in the prompt. It is off by default; see RAG pipeline.
5
Generation and response
The language model generates an answer using the retrieved context and your message. The response is returned as JSON or streamed as SSE.