Reasoning
One way to control and read a model's reasoning, whichever model serves the request.
The reasoning control#
reasoning.effort is none, low, medium or high, and reasoning.enabled switches reasoning on or off on models where it is optional. none is the same as enabled: false. Without either, the model's default applies. The gateway translates the control for the model that serves the request.
The samples read the model id from PANWARD_REASONING_MODEL: set it to a chat model with the reasoning capability from the model catalog. A model without it refuses the request with 400 unsupported_parameter before any upstream call, so nothing is billed.
cat > body.json <<EOF { "model": "$PANWARD_REASONING_MODEL", "messages": [{"role": "user", "content": "Which of these three dosing schedules gives the lowest daily total?"}], "reasoning": {"effort": "low"}, "max_completion_tokens": 4000 } EOF curl https://api.panward.ai/v1/chat/completions \ -H "Authorization: Bearer $PANWARD_API_KEY" \ -H "Content-Type: application/json" \ --data-binary @body.json
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=os.environ["PANWARD_REASONING_MODEL"], messages=[{"role": "user", "content": "Which of these three dosing schedules gives the lowest daily total?"}], reasoning_effort="low", max_completion_tokens=4000, ) message = reply.choices[0].message print(getattr(message, "reasoning_content", None)) # the reasoning, when the model returns it print(message.content) print(reply.usage.completion_tokens_details.reasoning_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: process.env.PANWARD_REASONING_MODEL!, messages: [{ role: "user", content: "Which of these three dosing schedules gives the lowest daily total?" }], reasoning_effort: "low", max_completion_tokens: 4000, }); const message = reply.choices[0].message as typeof reply.choices[0]["message"] & { reasoning_content?: string }; console.log(message.reasoning_content); // the reasoning, when the model returns it console.log(message.content); console.log(reply.usage?.completion_tokens_details?.reasoning_tokens);
The OpenAI-style shorthand#
reasoning_effort takes the same four values as reasoning.effort. If you send both they must agree; otherwise the request is refused with 400 invalid_request.
Read the reasoning#
When the model returns its reasoning, it is in message.reasoning_content, and in delta.reasoning_content in a stream, always under this name whichever model answered.
Tokens and cost#
Reasoning tokens count in completion_tokens, are reported in completion_tokens_details.reasoning_tokens, are billed as output, and count toward max_completion_tokens. Leave room for them when you set the limit.
Models without reasoning#
reasoning or reasoning_effort sent to a model without the reasoning capability is refused with 400 unsupported_parameter.
Reasoning in the conversation history#
An earlier assistant turn may carry its reasoning_content, and you can pass it back. Leaving it out keeps the input, and so the input cost, smaller.