Use reasoning models such as GPT-5.4 Pro and GPT-5 Pro for math, logic, and coding tasks.
POST /v1/chat/completions
## Create a reasoning chat completion GPT-5.4 Pro is OpenAI's next-generation **reasoning model**, built with an internal chain-of-thought reasoning chain, delivering significantly superior performance in complex scenarios compared to traditional chat models: - Complex mathematical derivations / proofs - Multi-step logical reasoning - Code generation / debugging / refactoring - Long-context deep analysis (supports 1M token context) ### Supported reasoning models | Model | Context Window | Output Limit | |---|---|---| | `gpt-5.4-pro` | 1M tokens | 128K tokens | | `gpt-5-pro` | 200K tokens | 100K tokens | ### Invocation method Completely consistent with standard chat completions; use the OpenAI standard SDK with no additional dependencies required: ```python from openai import OpenAI client = OpenAI(api_key="sk-xxx", base_url="https://api.router.ai/v1") resp = client.chat.completions.create( model="gpt-5.4-pro", messages=[{"role": "user", "content": "Solve: x^2 - 5x + 6 = 0"}], max_completion_tokens=500, ) print(resp.choices[0].message.content) print("Reasoning tokens:", resp.usage.completion_tokens_details.reasoning_tokens) ``` ### Protocol differences (differences from standard chat models) - Must use the `max_completion_tokens` field (not `max_tokens`); this field includes the sum of tokens consumed during reasoning and visible output tokens - Custom `temperature` is not supported (reasoning model behavior is fixed; any provided value will be ignored) - Streamed responses are not supported (`stream: true`) — please use synchronous calls and receive the full response after reasoning completes - The response `usage.completion_tokens_details.reasoning_tokens` field returns the token count of the reasoning process (transparently) - Optional parameter `reasoning_effort`: `"low"` / `"medium"` (default) / `"high"`, to control reasoning depth (deeper depth results in longer processing time) ### Recommended use cases | Use case | Recommended model | |---|---| | Simple conversations / casual chat | `gpt-4o` / `gpt-5.4` standard models (faster, cheaper) | | Math problems / algorithms / reasoning | `gpt-5.4-pro` | | Long-context analysis (codebase review / paper reading) | `gpt-5.4-pro` (1M context) | | Function calling (tool usage) | `gpt-5.4-pro` (native support) | > Reasoning model response latency is typically 10-30 seconds, significantly longer than standard chat models (1-3 seconds). Please set a reasonable client timeout (recommended ≥60 seconds).
model | string | required | Reasoning model ID: e.g. `gpt-5.4-pro` / `gpt-5-pro` |
messages | array | required | Conversation message array, each element containing `role` (system/user/assistant) + `content` (string or multimodal array) |
max_completion_tokens | integer | Maximum output token limit (including tokens consumed during reasoning and visible output tokens). The reasoning model uses this field — **do not use max_tokens** (deprecated) | |
reasoning_effort | string | Reasoning depth: `low` / `medium` (default) / `high`. The deeper the depth, the more detailed the reasoning, but the longer the inference time | |
tools | array | Tool calling definition, follows the OpenAI function calling specification | |
tool_choice | string | object | Tool calling strategy: `auto` / `none` / `required` / `{type:'function',function:{name:'X'}}` | |
stream | boolean | **Must be false currently**. Streaming inference for reasoning models is not supported; setting it to true will return 400 | |
user | string | User identifier, consistent with OpenAI, used for auditing and abuse tracking |
200 — Success. The `usage.completion_tokens_details.reasoning_tokens` field returns the token count consumed during reasoning. `completion_tokens` includes the sum of all reasoning tokens.400 — Request parameter error. Common issues: `stream=true` (streaming inference for reasoning models is not supported) / `max_tokens` is deprecated (use `max_completion_tokens` instead)curl -X POST https://api.router.ai/v1/chat/completions \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4-pro",
"messages": [
{"role": "user", "content": "Solve: x^2 - 5x + 6 = 0"}
],
"max_completion_tokens": 500,
"reasoning_effort": "medium"
}'