Chat completions
Send a conversation to POST /v1/chat/completions, control the output, and read the response, its headers and its receipt.
Send a conversation#
POST /v1/chat/completions takes a model (a canonical id) and messages, each with a role: system (or developer), user, assistant or tool.
curl https://api.panward.ai/v1/chat/completions \ -H "Authorization: Bearer $PANWARD_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "z-ai/glm-5.3", "messages": [ {"role": "system", "content": "You summarise clinical notes in three sentences."}, {"role": "user", "content": "Summarise this discharge note."} ], "max_completion_tokens": 300, "temperature": 0.2 }'
import os from openai import OpenAI client = OpenAI( base_url="https://api.panward.ai/v1", api_key=os.environ["PANWARD_API_KEY"], ) reply = client.chat.completions.create( model="z-ai/glm-5.3", messages=[ {"role": "system", "content": "You summarise clinical notes in three sentences."}, {"role": "user", "content": "Summarise this discharge note."}, ], max_completion_tokens=300, temperature=0.2, ) choice = reply.choices[0] print(choice.message.content) print(choice.finish_reason, reply.usage.total_tokens)
import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.panward.ai/v1", apiKey: process.env.PANWARD_API_KEY, }); const reply = await client.chat.completions.create({ model: "z-ai/glm-5.3", messages: [ { role: "system", content: "You summarise clinical notes in three sentences." }, { role: "user", content: "Summarise this discharge note." }, ], max_completion_tokens: 300, temperature: 0.2, }); const choice = reply.choices[0]; console.log(choice.message.content); console.log(choice.finish_reason, reply.usage.total_tokens);
Request fields#
| Field | Required | Values | Limits | Notes |
|---|---|---|---|---|
| model | Yes | string | Canonical model id. Aliases are not resolved. | |
| messages | Yes | array of ChatMessage | min items 1 | |
| max_completion_tokens | No | integer | min 1 | Upper bound on generated tokens, including reasoning tokens. Capped by the model's `max_output_tokens`. |
| max_tokens | No | integer | min 1 | Older name of `max_completion_tokens`. If both are sent they must be equal. |
| temperature | No | number | min 0; max 2 | |
| top_p | No | number | max 1 | |
| top_k | No | integer | min 1 | Not supported by every model. |
| frequency_penalty | No | number | min -2; max 2 | |
| presence_penalty | No | number | min -2; max 2 | |
| seed | No | integer | Best-effort determinism; the same seed and parameters usually give the same output on the same offer. | |
| stop | No | string | array of string | Up to 4 sequences at which generation stops. | |
| n | No | integer | min 1; max 1 | Number of choices. Only 1 is supported. |
| logprobs | No | boolean | ||
| top_logprobs | No | integer | min 0; max 20 | Needs `logprobs: true`. |
| stream | No | boolean | Return the response as an event stream. | |
| stream_options | No | object | Only valid with `stream: true`. | |
| tools | No | array of Tool | max items 128 | |
| tool_choice | No | string | object | `none`, `auto` (default when tools are present), `required`, or one named function. | |
| parallel_tool_calls | No | boolean | ||
| response_format | No | object | object | object | Output format. `json_schema` needs a model with the `json_schema` capability. | |
| reasoning | No | object | Canonical reasoning control, translated by the gateway for the model that serves the request. On a model without the `reasoning` capability it is rejected with `400 unsupported_parameter`. Reasoning tokens are billed as output tokens. | |
| reasoning_effort | No | none, low, medium, high | OpenAI-style shorthand for `reasoning.effort`. If both are sent they must agree. | |
| user | No | string | max length 256 | Accepted for compatibility and ignored. It is never stored and never forwarded upstream. |
Control the output#
max_completion_tokens bounds the tokens generated, reasoning tokens included, and is capped by the model's maximum output. temperature (0 to 2), top_p, stop (up to 4 sequences) and seed (best effort) work as in the OpenAI API. A project policy may cap the input size with prompt.max_input_tokens (Policies).
Read the response#
The answer is in choices[0].message: content, reasoning_content when the model returns its reasoning, refusal when the model declined, and tool_calls when it called a tool. finish_reason says why generation stopped, and usage holds the billed token counts.
{
"id": "chatcmpl-01JC7Q4N8G5T2R9X1M3K6P7W4D",
"object": "chat.completion",
"created": 1790000000,
"model": "z-ai/glm-5.3",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The clause limits each party's liability to the fees paid in the previous twelve months."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 1500,
"completion_tokens": 500,
"total_tokens": 2000,
"prompt_tokens_details": {
"cached_tokens": 0
},
"completion_tokens_details": {
"reasoning_tokens": 472
}
}
}Headers on every response#
| Header | Meaning |
|---|---|
| panward-request-id | Panward's id for this request (`req_…`). Quote it to support. |
| panward-receipt-id | Id of the receipt for this request (`rcpt_…`), on streamed and non-streamed responses and on refusals that produce a receipt (policy denial, no eligible Sealed offer, limit reached). Read it with `GET /receipts/{id}`. |
| panward-tier | Tier the request was served in. |
| panward-region | Gateway region that served the request. |
| panward-model | Canonical id of the model that answered. Differs from the requested model only when a fallback model was used. |
| panward-client-request-id | Echo of the request's `X-Request-Id`, when one was sent. |
| panward-ratelimit-limit | Request limit (requests per minute) of the current window: the tightest that applies (key, project or organization). |
| panward-ratelimit-remaining | Requests left in the current window of that limit. |
| panward-ratelimit-reset | Seconds until the current window resets. |
| panward-ratelimit-limit-tokens | Token limit (tokens per minute) of the current window: the tightest tokens-per-minute limit that applies to this request (key, project or organization). Sent only when such a limit applies. |
| panward-ratelimit-remaining-tokens | Tokens left in the current window of that limit (input, cached input included, and output, as counted). |
| panward-ratelimit-reset-tokens | Seconds until the current window of that limit resets. |
raw = client.chat.completions.with_raw_response.create( model="z-ai/glm-5.3", messages=[{"role": "user", "content": "Summarise this discharge note."}], ) for name, value in raw.headers.items(): if name.startswith("panward-"): print(f"{name}: {value}") reply = raw.parse()
Choose a tier#
Without a header the model's default tier applies. panward-tier asks for Sealed or Routed for one request, and panward-fallback: allow lets the project's fallback models answer when the requested model has no capacity. Tiers and routing headers explains both.
Multi-turn conversations#
Nothing is stored between requests: send the whole conversation each time, with earlier assistant turns and tool results. Tool-call ids from earlier turns are passed through as you send them.
reply = client.chat.completions.create( model="z-ai/glm-5.3", messages=[ {"role": "system", "content": "You summarise clinical notes in three sentences."}, {"role": "user", "content": "Summarise this discharge note."}, {"role": "assistant", "content": "The patient was admitted with pneumonia and treated with antibiotics."}, {"role": "user", "content": "Which follow-up does it ask for?"}, ], )
Prompt caching#
On models with the prompt_caching capability, input served from a cache that is isolated to your organization is reported in usage.prompt_tokens_details.cached_tokens and billed at the cached-input price.
Some model providers cache the start of recent prompts across all their customers, with no way to separate or switch off that cache, and Panward still uses them. There, cached input is billed at the full input price and cached_tokens is 0, so your usage and bill never show a cache hit. Another customer of that provider could notice a faster reply to a prompt opening sent recently, and so learn that someone sent it; the content of your prompts is not revealed this way. Receipts do not record whether such a cache was in use (Data handling).
Context length#
The input plus the maximum output must fit the model's context. Otherwise the request is refused with 400 context_length_exceeded before any upstream call, and nothing is billed.
{
"error": {
"type": "context_length_exceeded",
"message": "The input and max_tokens together exceed this model's context of 200000 tokens.",
"param": "max_tokens",
"request_id": "req_01JC7Q4N8G5T2R9X1M3K6P7W4D",
"doc_url": "https://panward.ai/docs/errors#context_length_exceeded"
}
}Timeouts#
The first byte is expected within 30 seconds, or you get a retryable 504 upstream_timeout or 502 upstream_unavailable. The total budget of a request is 600 seconds. Set your client's timeouts to match (Limits).
What is billed#
The tokens actually produced, at your organization's prices. Requests refused by Panward (authentication, policy, limits, validation) and upstream failures before any output are not billed (Credits, top-ups and limits).
The receipt#
Every response has a receipt, whose id is in the panward-receipt-id header. It binds the exact request and response bytes to Panward's attested gateway and states what the gateway verified about the upstream (Receipts and verification).
Checking a receipt shows
- The receipt was signed by Panward's gateway, running software whose measurements are on the published release list, in an enclave whose attestation Warden checked (steps 1 to 3).
- When you supply them, the request and response bytes you hold are the ones the gateway received and wrote (step 4).
- What the gateway states it verified about the upstream: the level, the signer scope and the evidence it relied on, named by content hash. This part is the gateway's statement. Warden reports it and does not check it against the upstream.
It does not show
- That the answer is correct. Models still make mistakes.
- What your own application does with the response afterwards.
- It does not establish which instance served the request, whether the GPU was in a protected state, or where the model's weights came from.
- Protection against someone with physical access to the hardware. Attestation protects against software and administrators. It cannot rule out someone with physical access to the hardware.
- Anything about confidentiality at the upstream for a Routed request: the upstream provider can read the prompt.