Text completions
Send a prompt and get text back on the legacy completions endpoint, for code written before chat completions.
When to use it#
POST /v1/completions is the legacy endpoint: a prompt goes in and text comes out. It takes models of kind completion or chat. Prefer chat completions for new code.
Completions are served Routed only: no supplier signs completion responses, so there is nothing to verify a Sealed answer against. A request for the Sealed tier (by panward-tier, or by default) is refused with 400 unsupported_parameter naming panward-tier, before any upstream call; use chat completions for Sealed traffic. The samples on this page send panward-tier: routed.
Request#
The OpenAI SDKs' completions call works with the base URL and key changed. Unknown fields are refused with 400 invalid_request.
curl https://api.panward.ai/v1/completions \ -H "Authorization: Bearer $PANWARD_API_KEY" \ -H "Content-Type: application/json" \ -H "panward-tier: routed" \ -d '{ "model": "z-ai/glm-5.3", "prompt": "Discharge summary:", "max_tokens": 200, "temperature": 0.2, "stop": ["###"] }'
import os from openai import OpenAI client = OpenAI( base_url="https://api.panward.ai/v1", api_key=os.environ["PANWARD_API_KEY"], ) raw = client.completions.with_raw_response.create( model="z-ai/glm-5.3", prompt="Discharge summary:", max_tokens=200, temperature=0.2, extra_headers={"panward-tier": "routed"}, ) completion = raw.parse() print(completion.choices[0].text) print(raw.headers["panward-receipt-id"])
import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.panward.ai/v1", apiKey: process.env.PANWARD_API_KEY, }); const { data: completion, response } = await client.completions .create( { model: "z-ai/glm-5.3", prompt: "Discharge summary:", max_tokens: 200, temperature: 0.2 }, { headers: { "panward-tier": "routed" } }, ) .withResponse(); console.log(completion.choices[0].text); console.log(response.headers.get("panward-receipt-id"));
| Field | Required | Values | Limits | Notes |
|---|---|---|---|---|
| model | Yes | string | ||
| prompt | Yes | string | array of string | ||
| max_tokens | No | integer | min 1 | |
| temperature | No | number | min 0; max 2 | |
| top_p | No | number | max 1 | |
| frequency_penalty | No | number | min -2; max 2 | |
| presence_penalty | No | number | min -2; max 2 | |
| seed | No | integer | ||
| stop | No | string | array of string | ||
| echo | No | boolean | ||
| logprobs | No | integer | min 0; max 5 | |
| stream | No | boolean | ||
| stream_options | No | object | Only valid with `stream: true`. | |
| user | No | string | max length 256 | Accepted for compatibility and ignored. Never stored, never forwarded upstream. |
Response#
The response is a text_completion object with a cmpl- id. Each choice has its text and a finish_reason, and usage holds the token counts that are billed.
{
"id": "cmpl-01JC7Q4N8G5T2R9X1M3K6P7W4D",
"object": "text_completion",
"created": 1790000000,
"model": "z-ai/glm-5.3",
"choices": [
{
"index": 0,
"text": " The patient was admitted with community-acquired pneumonia.",
"finish_reason": "stop",
"logprobs": null
}
],
"usage": {
"prompt_tokens": 4,
"completion_tokens": 12,
"total_tokens": 16
}
}Streaming#
With stream: true the response uses the same event-stream framing as chat completions, with text_completion chunks that carry partial text, ended by data: [DONE]. Usage is sent only when stream_options.include_usage is true, in the final chunk.
curl -N https://api.panward.ai/v1/completions \ -H "Authorization: Bearer $PANWARD_API_KEY" \ -H "Content-Type: application/json" \ -H "panward-tier: routed" \ -d '{ "model": "z-ai/glm-5.3", "prompt": "Discharge summary:", "max_tokens": 200, "stream": true, "stream_options": {"include_usage": true} }'
The streaming page covers the frames, errors after the first byte and how to keep the raw stream for verification.
Headers, receipts and errors#
Text completions take the same request headers, routing, receipts and errors as chat completions: panward-tier, panward-fallback, panward-hold-until-verified and X-Request-Id on the request, and panward-receipt-id, panward-tier, panward-region and panward-model on the response (Tiers and routing headers, Receipts and verification, Errors).