Skip to main content
The Chat Completions endpoint follows the OpenAI wire format exactly, which means any OpenAI-compatible client — the Python openai library, openai-node, LangChain, LlamaIndex — works with Ragen by pointing base_url at your instance. You get the full Ragen RAG pipeline (vector retrieval → reranking → generation) behind a familiar interface, plus multi-turn conversations, per-request model and temperature overrides, and opt-in usage tracking in streams.

Endpoint

Authentication:
API keys are scoped to your organization. Create and manage them under Organization → API keys in the dashboard.
Enable debug mode on your API key to save every API conversation as a thread visible under the project’s API threads tab. This lets you inspect the full request and response during development without adding logging to your code.

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, and a Ragen extension the OpenAI wire format has no field for — which is the point: an OpenAI-compatible client that cannot send it works against this endpoint, because the API key already carries the scope. Retrieve available IDs from GET /v1/assistants or from Organization → Assistant settings in the dashboard.
array
required
An array of 1–100 message objects in conversation order. Each message has a role (user, assistant, or system) and a content string. See Message roles below.
string
Override the organization’s default model for this request only. Must be a model available to your organization.
number
Sampling temperature between 0 and 2. Overrides the organization default for this request.
integer
Maximum number of tokens to generate, between 1 and 32,000.
string
One of "low", "medium", or "high". Forwarded to the model; only reasoning-capable models act on it (they default to "medium").
boolean
default:"false"
When true, the response is delivered as a Server-Sent Events stream of chat.completion.chunk objects.
object
Streaming options. Pass { "include_usage": true } to receive a trailing usage chunk after [DONE]. See Including usage in streams.
boolean
default:"false"
Ragen extension. When true, the response also lists the documents the answer was drawn from. See Including sources. Off by default, so an OpenAI client sees exactly the format it expects.

Message roles

Rejected fields

Most additional OpenAI parameters are accepted and silently ignored (e.g. top_p, stop, seed). The following three fields are rejected with a 400 error because silently dropping them would return a response that violates what you asked for: n greater than 1 is also rejected: Ragen returns one choice, so asking for several would silently under-deliver.

Response

Non-streaming

Returns a standard chat.completion object:

Streaming

When stream: true, returns text/event-stream with a sequence of chat.completion.chunk objects terminated by data: [DONE]:
  • The first chunk carries delta.role: "assistant" (OpenAI convention).
  • Content chunks carry delta.content.
  • The final chunk before [DONE] has an empty delta and finish_reason: "stop".

Including usage in streams

Pass stream_options: { include_usage: true } to receive a trailing usage chunk inserted between the final content chunk and data: [DONE]:
The empty choices: [] signals that this chunk carries usage data only.

Examples

Error codes

Errors use the OpenAI error envelope, so existing SDK error-handling continues to work:

Rate limits

Chat Completions run a full RAG pipeline (hybrid search, reranking when the deployment enables it, and an LLM call): Both streaming and non-streaming requests count equally. When the limit is hit, back off with jitter before retrying.

Including sources

Set ragen_sources: true to get the documents the answer was drawn from — the files retrieval put in front of the model, most relevant first. The field is namespaced with ragen_ so it can never collide with one OpenAI adds later, and clients that do not ask never see it. In a non-streaming response it is a top-level field of the completion object:
When streaming, it arrives as one trailing chunk with choices: [] — like the usage chunk — after the final content chunk and any usage chunk, and before data: [DONE]:
Each source has fileId, fileName (null for documents ingested before names were stored), and rank (1 is the most relevant). When the file is a published Ragen Brain page it also has brain, with the page’s pageTitle and the sources it was built from (fileName and the span locating the passage). Only documents the API key may read are listed. An answer that a guardrail withheld returns "ragen_sources": [].

Differences vs. POST /v1/chat

The native POST /v1/chat endpoint predates this one and offers a simpler interface (single content string, optional context). Both are supported: Use /v1/chat/completions for any new integration. Keep /v1/chat for the Ragen embed widget and other existing Ragen-native consumers.