Skip to main content
Menu
Build / Chat completions
Build

Chat completions

Send a conversation to POST /v1/chat/completions, control the output, and read the response, its headers and its receipt.

8 minute readUpdated 13 November 2026curl · Python · TypeScript

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
  }'

Request fields#

FieldRequiredValuesLimitsNotes
modelYesstringCanonical model id. Aliases are not resolved.
messagesYesarray of ChatMessagemin items 1
max_completion_tokensNointegermin 1Upper bound on generated tokens, including reasoning tokens. Capped by the model's `max_output_tokens`.
max_tokensNointegermin 1Older name of `max_completion_tokens`. If both are sent they must be equal.
temperatureNonumbermin 0; max 2
top_pNonumbermax 1
top_kNointegermin 1Not supported by every model.
frequency_penaltyNonumbermin -2; max 2
presence_penaltyNonumbermin -2; max 2
seedNointegerBest-effort determinism; the same seed and parameters usually give the same output on the same offer.
stopNostring | array of stringUp to 4 sequences at which generation stops.
nNointegermin 1; max 1Number of choices. Only 1 is supported.
logprobsNoboolean
top_logprobsNointegermin 0; max 20Needs `logprobs: true`.
streamNobooleanReturn the response as an event stream.
stream_optionsNoobjectOnly valid with `stream: true`.
toolsNoarray of Toolmax items 128
tool_choiceNostring | object`none`, `auto` (default when tools are present), `required`, or one named function.
parallel_tool_callsNoboolean
response_formatNoobject | object | objectOutput format. `json_schema` needs a model with the `json_schema` capability.
reasoningNoobjectCanonical 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_effortNonone, low, medium, highOpenAI-style shorthand for `reasoning.effort`. If both are sent they must agree.
userNostringmax length 256Accepted 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.

A response (the contract's example)
{
  "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#

HeaderMeaning
panward-request-idPanward's id for this request (`req_…`). Quote it to support.
panward-receipt-idId 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-tierTier the request was served in.
panward-regionGateway region that served the request.
panward-modelCanonical id of the model that answered. Differs from the requested model only when a fallback model was used.
panward-client-request-idEcho of the request's `X-Request-Id`, when one was sent.
panward-ratelimit-limitRequest limit (requests per minute) of the current window: the tightest that applies (key, project or organization).
panward-ratelimit-remainingRequests left in the current window of that limit.
panward-ratelimit-resetSeconds until the current window resets.
panward-ratelimit-limit-tokensToken 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-tokensTokens left in the current window of that limit (input, cached input included, and output, as counted).
panward-ratelimit-reset-tokensSeconds until the current window of that limit resets.
Print the panward-* headers of a response
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.

Send the whole conversation each time
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.

400 when the input and the maximum output do not fit the context
{
  "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.
Was this page helpful?Suggest an edit