Chat completions
OpenAI-compatible chat completions on Pendra, with streaming, tools, thinking and structured outputs.
model
string
Required
qwen3.6:27b. Leave off the quant to use
whichever one you have installed. See Naming a model.
messages
array
Required
{ role, content } objects with role
system, user, assistant or
tool. A user message's content can be a string or
a list of text, image_url
(vision) and file
parts (a text or CSV file up
to 1 MB). See also
System messages
and thinking in longer conversations.
stream
boolean
default: false
max_tokens
integer
default: 32,768
max_completion_tokens
is accepted too, and wins if you send both.
temperature
number
default: the model's recommended value, else 1.0
0 to 2. Use
0 for the most focused, repeatable answers.
tools
array
response_format
object
reasoning_effort
string
"low", "medium",
"high", "xhigh" or "max", or
"none" to turn thinking off. A level the model lacks rounds up.
See Thinking.
reasoning
object
{ "max_tokens": 4096 } caps thinking at that many tokens, then
the model moves on to its answer. 0 turns thinking off. The
default is 8,192 on models that support it. { "effort": "low" }
is the same as reasoning_effort. See
Thinking budget.
enable_thinking
boolean
false makes a reasoning model answer straight away,
true makes it think. Most reasoning models think by default.
See Thinking.
seed
integer
temperature is above
0.
Other fields
| Field | Type | What it does |
|---|---|---|
top_p | number | Nucleus sampling, from 0 to 1. 1 is off. |
top_k | integer | Keep only the K most likely tokens. 0 is off. |
min_p | number | Drop tokens less likely than min_p times the top token. |
stop | string or array | Stop when the model writes one of these. |
frequency_penalty | number | Penalise tokens by how often they've appeared, from -2 to 2. |
presence_penalty | number | Penalise tokens that have appeared at all, from -2 to 2. |
repeat_penalty | number | Classic repetition penalty. 1.0 is off, 1.1 to 1.3 discourages repeats. |
repeat_last_n | integer | How many recent tokens repeat_penalty looks at. Default 64. |
logit_bias | object | Make tokens more or less likely, keyed by token id, from -100 to 100. |
logprobs, top_logprobs | boolean, integer | Return how likely each token of the answer was, and up to 20 alternatives per token. See Token probabilities. |
xtc_probability | number | How often the most likely tokens are set aside for a less obvious one, from 0 to 1. Helps creative writing. 0 is off. |
xtc_threshold | number | How likely a token must be to count as a top choice for XTC, from 0 to 0.5. Default 0.1. |
mirostat | integer | 1 or 2 turns on Mirostat, which keeps the text at a steady level of surprise instead of using top_p, top_k and min_p. 0 is off. |
mirostat_tau | number | Mirostat's target. Lower is more focused, higher more varied. Default 5.0. |
mirostat_eta | number | How fast Mirostat corrects towards its target. Default 0.1. |
-
Any sampling field you leave out uses the model authors' recommended
value, listed as
sampling_defaultsin the models list. - Any other OpenAI field is passed to the model as it is.
-
Even at
temperature: 0, a reply can differ by the odd token between runs, because of tiny differences in GPU maths. For extraction where missing an item is costly, run it twice and combine the results.
Response
A chat.completion object, as in the example.
-
finish_reasonis"stop"when the model finished, or"length"when it hit a limit. -
A reasoning model's thinking is in
message.reasoning_content(alsomessage.reasoning), separate from the answer inmessage.content. -
usage.prompt_tokens_details.cached_tokenscounts the prompt tokens reused from earlier turns. More reuse means a faster first token. See KV cache. -
The
pendrafield adds which worker served it, timing and any notice. OpenAI clients ignore it.
Streaming
With stream: true, the reply arrives as server-sent events in
OpenAI's format: data: { ... } lines, each a
chat.completion.chunk, ending with data: [DONE].
curl https://api.pendra.ai/api/v1/chat/completions \
-H "Authorization: Bearer pdr_sk_..." \
-N \
-d '{
"model": "qwen3.6:27b",
"stream": true,
"messages": [{"role": "user", "content": "Hello"}]
}'
-
The last chunks carry
usageandpendra.timingwith an emptychoicesarray, so don't readchoices[0]without checking. -
Tool call
argumentsarrive in pieces ondelta.tool_calls. See Stream tool calls. -
While a long prompt is read, Pendra sends a
: keep-alivecomment every 15 seconds. Clients ignore it. If you parse the stream yourself, skip lines starting with:.
data: {"id":"chatcmpl-9f2b","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-9f2b","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}],"usage":{"prompt_tokens":8,"completion_tokens":2,"total_tokens":10}}
data: {"id":"chatcmpl-9f2b","object":"chat.completion.chunk","choices":[],"pendra":{"timing":{"ttft_ms":115,"tokens_per_second":58.34}}}
data: [DONE]
Errors on a stream
Anything Pendra knows before the reply starts, such as an unknown model, no worker online, or every worker busy, comes back as a normal HTTP error before any stream data. When every worker is busy, Pendra waits up to about 30 seconds for one first, so give your client a timeout of at least 90 seconds for the headers.
If the request fails after the stream has started, for example if a
worker goes offline, the last chunk has finish_reason: "error"
and an error object, followed by data: [DONE].
code is the HTTP status it would have had. The Pendra and
OpenAI SDKs raise this as an error.
data: {"object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"error"}],"error":{"message":"the prompt is 8800 tokens, which exceeds the context window of 1024 tokens on this worker","type":"worker_error","code":400}}
Token probabilities
Set logprobs: true to get how likely the model thought each
token of its answer was. Add top_logprobs (0 to 20) to also get
the most likely alternatives at each position. It's handy for classifying
with a confidence score, or for spotting where an answer was a guess. The
example turns thinking
off so its one token is the answer.
curl https://api.pendra.ai/api/v1/chat/completions \
-H "Authorization: Bearer pdr_sk_..." \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.6:27b",
"messages": [
{
"role": "user",
"content": "Is this review positive? Answer yes or no. Review: Great battery, fast delivery."
}
],
"enable_thinking": false,
"max_tokens": 1,
"logprobs": true,
"top_logprobs": 2
}'
"logprobs": {
"content": [
{
"token": "Yes",
"logprob": -0.0021,
"bytes": [89, 101, 115],
"top_logprobs": [
{ "token": "Yes", "logprob": -0.0021, "bytes": [89, 101, 115] },
{ "token": "No", "logprob": -6.18, "bytes": [78, 111] }
]
}
],
"refusal": null
}
-
A logprob is a natural log, so
exp(logprob)is the probability. -0.0021 is 99.8%. -
Only the answer is covered. Thinking and tool calls have no entries, so a
reply that calls a tool has an empty
contentlist. -
The probabilities are the model's own, before
temperatureand the other sampling settings. When streaming, each chunk carries the entries for its own text. -
It needs an up-to-date worker. If no worker serving the model has
updated yet, the request fails with a 400 whose
codeislogprobs_unsupported, rather than answering without them. Pendra can't check an end-to-end encrypted request this way, so keep those workers up to date.
Notices
pendra.notice explains a reply that might otherwise look
wrong. It has a code to check in your code and a
message that says what to do. A reply has at most one.
| Code | What happened | What to do |
|---|---|---|
truncated_during_reasoning | A reasoning model used all of max_tokens thinking, so there's no answer. | Raise max_tokens, or turn thinking off. |
reasoning_budget_reached | Thinking hit its budget and was ended there. The answer is complete. | Raise the budget if you want more thinking. |
truncated_at_reasoning_budget | Thinking hit its budget on a model that can't move on to its answer, so there's no answer. | Raise the budget, or turn thinking off. |
truncated_at_default_max_tokens | You set no max_tokens and the reply reached the default limit. | Set max_tokens. |
truncated_during_structured_output | The reply stopped before its JSON was complete. | Raise max_tokens, or shorten the prompt. |
context_window_exhausted | The prompt and reply filled the model's context window. | Raise the context on the worker, or shorten the prompt. |
truncated_memory_full | The worker's memory was full of other requests, so it ended this one early. | Retry, or run fewer requests at once on the worker. |
structured_output_not_json | You asked for JSON and the reply isn't JSON. | The message says whether to retry or simplify the schema. |
strict_schema_not_enforced | Part of your strict schema couldn't be enforced. | Check the reply against your schema before using it. |
For more, see Thinking budget, Structured outputs, Context and Requests at once. On a stream, the notice comes on a chunk just before the last one.
If a long conversation's oldest images were left out to fit the worker's
memory, pendra.images_omitted says how many. See
Lots of images.
Timing
pendra.timing reports each reply's speed. A normal reply has
it next to choices, and a stream has it on the last chunk.
Each field is there only when it was measured.
| Field | Meaning |
|---|---|
ttft_ms | Time to first token, in ms. Queue time is reported separately. With web tools on, it includes any searches before the first token. |
tokens_per_second | How fast the reply was written. |
queue_wait_ms | How long the request waited before it started. |
worker_queue_wait_ms | How much of that wait was on the worker that served it. The rest was waiting for any worker to be free. |
model_load_ms | Time spent loading the model, on a cold start only. |
cold_start | true when the model had to be loaded for this request. |
draft_acceptance_rate | With speculative decoding, the share of draft tokens the model kept, from 0 to 1. |
A long worker_queue_wait_ms means that worker is busy, so
lower its requests at once.
A long wait for any worker means you need more workers.
Which worker served the request
pendra.worker names the worker that ran the request, so you
can check where it ran or trace a slow reply. A normal reply has it next
to choices, and a stream on the last chunk.
"pendra": {
"worker": {"id": "wrk-1a2b3c4d", "name": "london-gpu-01", "version": "3.115.1"},
"request_id": "3f1c8a2e-5b7d-4e19-9c0a-6d2f8b1e4a73"
}
| Field | Meaning |
|---|---|
worker.id | The worker's id. Send it as X-Pendra-Worker-Id to use the same worker again. |
worker.name | The worker's name in the console, or null. |
worker.version | The worker release that served the request, or null. Log it, because the console only shows the current version. |
request_id | The request's id. Quote it to support. |
If a worker fails the request, the error names it as
error.worker_id.
Web tool steps
When a worker has web tools on,
the model can search the web and read pages while it answers. Each step is
listed in pendra.web_tool_steps, or sent one at a time as
pendra.web_tool_step on a stream. Each has a
name (web_fetch or web_search),
arguments, ok, a short result,
result_chars, and error if it failed.
"pendra": {
"web_tool_steps": [
{ "index": 0, "name": "web_fetch", "arguments": "{\"url\":\"https://example.com\"}",
"ok": true, "result": "Example Domain...", "result_chars": 129 }
]
}
Response headers
| Header | Meaning |
|---|---|
X-Request-Id | The request's id. Quote it to support. |
X-Worker-Id | The worker the request went to. |
X-Worker-Name | That worker's name. A name with accents or other non-ASCII characters is URL-encoded after a UTF-8'' prefix. |
Server-Timing | ttft, tps, queue and worker_queue, the same figures as pendra.timing. Non-streaming replies only. |
Server-Timing: ttft;dur=115, tps;dur=0;desc="58.3", queue;dur=16600, worker_queue;dur=14100
Headers are sent before the reply is written, so on a slow request they
can be missing or name the first worker tried. The pendra
field in the body is always right, so read it from there.
Timeouts
A request can run for up to about 30 minutes. After about 80 seconds, Pendra keeps the connection open for you, so you don't need to stream just to avoid a timeout. If such a request fails, the error arrives in the body. See Errors on a slow request.
Using an OpenAI client
Set the base URL to https://api.pendra.ai/v1 and the API key
to your Pendra key. Nothing else changes. models.list() works
too, but returns only model ids. See
Models.