Chat
Chat completions
OpenAI’s Chat Completions API, for every text model: the same request and response, the same streaming, the same SDKs.
/v1/chat/completionsRequest
modelstringrequired- A model ID from the models page, such as
claude-opus-5-5orgpt-6-sol. messagesarrayrequired- The conversation:
system(ordeveloper),user,assistantandtoolmessages.contentis a string, or an array of parts to add images, PDFs, audio or video. streamboolean- Send the answer as server-sent events while it’s written. See Streaming below.
stream_optionsobject{ "include_usage": true }adds a final chunk with token usage.max_completion_tokensinteger- The most tokens to generate, reasoning included.
max_tokensworks too. temperaturenumber- 0 to 2. Lower is more focused, higher more varied. Some reasoning models ignore it. Claude from Opus 4.7 on (Opus 5 and 5.5, Fable 5, 5.1 and 5.2, Sonnet 5.5, Haiku 5.5) doesn’t take it, so we leave it out for those models.
top_pnumber- Nucleus sampling, 0 to 1. Change this or temperature, not both. Left out for the same Claude models, as top_k is.
stopstring | array- Up to 4 sequences where generation stops.
toolsarray- Functions the model may call. See Tool calling below.
tool_choicestring | objectauto,none,required, or a specific function. Where a model’s lab refuses or ignores one (a forced tool on Claude Opus 5.5, Sonnet 5.5, Fable 5.1 and Fable 5.2;noneon some Gemini, DeepSeek Flash, MiMo and MiniMax models), we send it in a form the model keeps to and tell the model what you asked for; a function forced by name goes as the only one offered.response_formatobject- JSON output:
{ "type": "json_object" }, orjson_schemawith a schema. See Structured output below. reasoning_effortstring- How hard a reasoning model thinks:
none,minimal,low,medium,high,xhighormax. Each model takes some of these (see Reasoning below); another level runs at the closest one it takes. Higher thinks longer and costs more output tokens. seedinteger- Best-effort reproducibility, for models that support it.
modelsarray- Smart routing for this request: alternatives to try, in order, if the model is down. See Smart routing.
user and metadata, which stay with us. Which ones a model honors (tools, JSON schemas, reasoning) is up to the model, as it is with its own lab. With the OpenAI Python SDK, send models as extra_body={"models": [...]}.Response
{ "id": "chatcmpl-AbC123...", "object": "chat.completion", "created": 1790870400, "model": "claude-opus-5-5", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "Here's the summary..." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 1204, "completion_tokens": 312, "total_tokens": 1516, "prompt_tokens_details": { "cached_tokens": 1024 }, "completion_tokens_details": { "reasoning_tokens": 128 } }}modelis the model that answered. It’s the one you asked for, unless smart routing answered with an alternative.- Reasoning models may add
reasoning_contentto the message: the model’s thinking, when it shares it. usageis what you’re billed for.cached_tokensare input tokens read from the model’s prompt cache, billed at the cached price where a model has one.
Every response also has these headers:
Streaming
With stream: true, the answer arrives as server-sent events in OpenAI’s chunk format, ending with data: [DONE]. Every SDK reads these for you.
import osfrom openai import OpenAIclient = OpenAI( base_url="https://api.zurelay.com/v1", api_key=os.environ["ZURELAY_API_KEY"],)stream = client.chat.completions.create( model="claude-sonnet-5-5", messages=[ { "role": "user", "content": "Write a limerick about databases." } ], stream=True, stream_options={ "include_usage": True },)for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True)- No answer is sent until the model has produced its first token, so a retry or a switch to another path stays invisible to you.
- Quiet stretches (a model thinking between steps) are filled with SSE comment lines (
: keep-alive) every 15 seconds. Clients ignore them; they keep proxies from closing the connection. If the first token takes more than 20 seconds (a long prompt, or a path that stalled and is being replaced), the stream opens then: the headers and keep-alive comments arrive while you wait. Each path gets up to 3 minutes to start (5 at high reasoning effort) before the next is tried, so set your client’s timeout to 10 minutes. - A stream that opened before its first token carries
x-zurelay-modelonly when no other model can answer it (smart routing off), and an error after it opened arrives as an error event in the stream (the same shape as the error body) instead of an error status. - With
include_usage, the last chunk before[DONE]has an emptychoiceslist and theusage.
Tool calling
Describe functions in tools; when the model wants one, it answers with tool_calls instead of text. Run the function, send the result back as a tool message with the call’s ID, and the model continues.
Only function tools are supported. Custom tools (type: "custom", with free-form or grammar input) are refused with a 400: send the tool as a function with a string parameter instead.
import osfrom openai import OpenAIclient = OpenAI( base_url="https://api.zurelay.com/v1", api_key=os.environ["ZURELAY_API_KEY"],)response = client.chat.completions.create( model="gpt-6-sol", messages=[ { "role": "user", "content": "What's the weather in Lisbon right now?" } ], tools=[ { "type": "function", "function": { "name": "get_weather", "description": "Current weather for a city", "parameters": { "type": "object", "properties": { "city": { "type": "string" } }, "required": [ "city" ] } } } ],)print(response.choices[0].message.content)Structured output
Ask for JSON with response_format. A json_schema holds models that support it to your schema; json_object asks for any valid JSON (say so in your prompt too).
import osfrom openai import OpenAIclient = OpenAI( base_url="https://api.zurelay.com/v1", api_key=os.environ["ZURELAY_API_KEY"],)response = client.chat.completions.create( model="gpt-6.1-sol", messages=[ { "role": "user", "content": "Extract the people: 'Ana met Ben and Chloe in Porto.'" } ], response_format={ "type": "json_schema", "json_schema": { "name": "people", "schema": { "type": "object", "properties": { "names": { "type": "array", "items": { "type": "string" } } }, "required": [ "names" ] } } },)print(response.choices[0].message.content)Reasoning
Reasoning models think before they answer. Set reasoning_effort to trade speed and cost for depth: a higher level thinks longer, takes more time and uses more output tokens. Each model takes the levels its lab documents, from none (no thinking) through minimal, low, medium, high and xhigh (extra high) to max; the table below lists them. Leave it out and the model uses its default. It works the same with any OpenAI SDK, and you can try each level in the dashboard’s Playground.
from openai import OpenAIclient = OpenAI(base_url="https://api.zurelay.com/v1", api_key="YOUR_ZURELAY_KEY")response = client.chat.completions.create( model="zurelay-auto", reasoning_effort="high", messages=[{"role": "user", "content": "How many primes are there below 1,000?"}],)message = response.choices[0].messageprint(getattr(message, "reasoning_content", None)) # the thinking, when the model shares itprint(message.content)The thinking comes back with the answer in message.reasoning_content (when streaming, in delta.reasoning_content) for models that share it; a few name the field reasoning. It’s billed as output tokens and is always part of completion_tokens; completion_tokens_details.reasoning_tokens counts it separately when the model reports that. At high effort an answer can take minutes to start, so give your client a generous timeout (see Reliability and timeouts).
Levels for each model
From each lab’s own documentation. A level a model doesn’t take runs at the closest one it does (of two equally close, the lower; and thinking only goes off when you send none), so one request works on every model, smart routing included. The x-zurelay-reasoning-effort response header says which level ran. A word that isn’t a level is refused with a 400 that lists the model’s levels.
Claude’s thinking
Through this endpoint, Claude takes reasoning_effort like any other model: low, medium, high, xhigh or max (Opus 4.6 has no xhigh). In Anthropic’s own format, Claude thinks adaptively at a level: send thinking: { type: "adaptive", display: "summarized" } with output_config: { effort: "xhigh" } and read the thinking blocks. See Anthropic Messages.
Questions, or something missing? Ask our support team and we’ll answer by email, usually within a minute.