Create Chat Completion
Generate a model response from a message array, with support for token streaming, JSON Patch streaming, and tool calling.
chat/completions endpoint. If an SDK defaults to the newer OpenAI Responses API, configure it to use chat completions instead.
Base URL
https://api.dottxt.ai/v1
Structured output
Useresponse_format with type: "json_schema" to constrain the model output to your schema.
category is always one of the four enum values. summary is between 10 and 120 characters. tags has 1–4 items. See the supported features for the full list of enforceable constraints.
JSON Patch streaming
Setstream: "patch" alongside a response_format JSON schema to stream the structured response field-by-field as JSON Patch operations instead of returning a single completion. The server emits one RFC 6902 add operation per field as the model generates it, so downstream work (routing, dispatching, UI updates) can begin the moment the relevant field lands.
stream: "patch" is the only request difference from a normal structured-output call — messages, temperature, max_tokens, seed, and the rest of the chat-completions parameters all behave the same way.
Wire format
The default response framing is NDJSON (Content-Type: application/x-ndjson): one JSON object per line, no event: prefix, no trailing terminator record — the stream ends when the connection closes.
Accept: text/event-stream on the request, and you’ll get:
event: done record before the connection closes; NDJSON closes silently.
Operation shape
Every record is an RFC 6902add operation:
op— always"add"in this mode.path— JSON Pointer to the location being filled in. The root document arrives first aspath: ""withvalue: {}(orvalue: []for array-rooted schemas).value— the value being inserted. For leaf fields, the JSON primitive (string, number, boolean, null). For nested objects and arrays, an empty container that subsequent ops will fill.
Order of operations
Operations arrive in schema order:- Root seed —
{"op":"add","path":"","value":{}}opens the document. For array-rooted schemas,valueis[]. - Leaf adds in schema order — top-level scalar fields like
intent,urgency,reply. - Container seeds + items — when the schema contains nested objects or arrays, the container is seeded first with
{}or[], then each item arrives as a separate add (/steps/0,/steps/1, …). Nested objects work the same way (/address, then/address/city,/address/zip).
{intent, urgency, steps: [...], reply} schema:
Reconstructing the document
Each op is applied to the document state from the previous op. If you collect every op and apply them in order, you end up with the same JSON object a non-streaming request would have returned. The Python SDK exposes the running snapshot directly viaevent.snapshot; see JSON Patch Streaming for details.
Patch streaming errors
- The stream opens with
200 OKonce the model starts emitting. Validation errors (bad schema, malformed request, auth failure) come back as the standard JSON error response before any patch records are sent. - A non-200 status means no patch records will arrive; read the body for the error payload.
- Connection failures mid-stream surface as a closed stream without a terminator. The Python SDK turns these into
dottxt.PatchStreamError.
Plain chat
Example response shape
Notes
- Set
stream: trueto receive token deltas as server-sent events; setstream: "patch"for JSON Patch streaming. - For the Python SDK helper that consumes patch streams into
PatchEventobjects, see JSON Patch Streaming. - For model discovery, call
GET /models. - For auth setup, see Authentication.
- For failures, inspect the HTTP status and the
errorobject in the response body.
Authorizations
API key authentication. Include your key in the Authorization header:
Authorization: Bearer YOUR_API_KEY
API keys can be created and managed in the dashboard.
Body
Request body for chat completions.
A list of messages comprising the conversation so far.
ID of the model to use.
"Qwen/Qwen3-30B-A3B-FP8"
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far.
0
The maximum number of tokens to generate in the chat completion.
256
How many chat completion choices to generate for each input message.
1
Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far.
0
Up to 4 sequences where the API will stop generating further tokens.
Output format for structured responses. Set to {"type": "json_schema", "json_schema": {...}} to constrain the response to a JSON schema. Required when stream is "patch".
Random seed for sampling. If provided and supported by the model, sampling is deterministic.
Streaming mode. false/unset returns a single JSON response. true streams token deltas as SSE. "patch" streams one JSON Patch add per schema field — see the JSON Patch streaming reference.
false
What sampling temperature to use, between 0 and 2.
0.7
Controls which (if any) tool is called by the model.
A list of tools the model may call.
An alternative to sampling with temperature, called nucleus sampling.
1
A unique identifier representing your end-user.
Response
Chat completion generated successfully. Response framing depends on the stream parameter and Accept header:
- Default (
streamunset orfalse): a single JSONChatCompletionResponse. stream: true: an SSE stream of token deltas.stream: "patch": an NDJSON stream ofJsonPatchOperationrecords (one per line), or SSE ifAccept: text/event-streamis sent.
Response from chat completions.
A list of chat completion choices.
The Unix timestamp of when the chat completion was created.
1703187200
A unique identifier for the chat completion.
"chatcmpl-abc123"
The model used for the chat completion.
"Qwen/Qwen3-30B-A3B-FP8"
The object type, always "chat.completion".
"chat.completion"
The system fingerprint of the model.
Usage statistics for the completion request.
{
"completion_tokens": 36,
"prompt_tokens": 24,
"total_tokens": 60
}