Reasoning Token Counting
On this page
Lesson rewritten on November 3, 2026 based on the xAI API reference (Chat Completions and Responses), the Reasoning guide, and the Reasoning Effort Evals example from the cookbook: at xAI,
completion_tokens(oroutput_tokens) counts only the visible response, reasoning is counted separately, and the total adds all three; the output limit does not cap reasoning. The previous version claimed the opposite, used Chat Completions fields on a Responses API reply, set effort ongrok-4.20-0309-reasoningwhich does not accept it, and showed a screenshot that did not match the API; these elements are corrected or removed. Sources: Chat Completions · Responses · Reasoning Effort Evals.
Understand reasoning tokens
Reasoning models produce two kinds of tokens: those for the visible response, and those for the model’s internal thought process. Understanding how xAI counts them is essential to master your costs and read your dashboards correctly.
The usage object in Chat Completions
Every response includes a usage object that details consumption. Here is the example from the xAI Chat Completions API reference:
{
"usage": {
"prompt_tokens": 32,
"completion_tokens": 9,
"total_tokens": 135,
"completion_tokens_details": {
"reasoning_tokens": 94
}
}
}
In this example:
- prompt_tokens (32): tokens in the input message
- completion_tokens (9): tokens in the visible response
- reasoning_tokens (94): tokens devoted to internal reasoning
- total_tokens (135): the sum of all three, 32 + 9 + 94
Reasoning is therefore not included in completion_tokens: it is added to it. Watch out if you come from another API where the convention differs, or if your dashboard calculates the visible response by subtraction.
Access reasoning tokens in code
In the Responses API, the same information carries different names: input_tokens, output_tokens for the visible response, and output_tokens_details.reasoning_tokens for reasoning.
response = client.responses.create(
model="grok-4.7",
input="Solve the integral of x^2 * e^x dx.",
reasoning={"effort": "high"},
)
visible_response = response.usage.output_tokens
reasoning = response.usage.output_tokens_details.reasoning_tokens
billed_output = visible_response + reasoning
print(f"Reasoning tokens: {reasoning}")
print(f"Response tokens: {visible_response}")
print(f"Reasoning share: {reasoning / billed_output * 100:.0f}%")
You set effort on grok-4.7, grok-4.6, and grok-4.5; grok-4.20-0309-reasoning always reasons, with no effort parameter.
Billing at the output rate
Reasoning tokens are billed at the output token rate, as the Reasoning Effort Evals example in the xAI cookbook reminds us. For grok-4.7 at $6 per million output tokens (prompt under 200,000 tokens), each reasoning token costs the same as a response token.
Effort therefore weighs on the bill, but not always as much as you might imagine. In this same example, across thirty short support tickets handled by grok-4.7, medium, high, and xhigh efforts consumed about the same amount of reasoning—around 600 tokens per response—while low consumed about 140 and cost half as much, with scores all between 87 and 93%. Measure on your own data before choosing.
Cost calculation example
# grok-4.7: $6.00/M output tokens (prompt < 200k)
cost_per_token = 6.00 / 1_000_000
reasoning = 600
visible_response = 350
billed_output = reasoning + visible_response # 950
cost = billed_output * cost_per_token
print(f"Output cost: ${cost:.4f}") # $0.0057
The role of max_completion_tokens
The output cap—max_completion_tokens in Chat Completions, max_output_tokens in the Responses API—applies only to the visible response: according to the API reference, reasoning tokens and function calls do not count toward it. Without a value, it defaults to 128,000 tokens. To limit reasoning, you need to set effort (lesson 10).
{
"model": "grok-4.7",
"messages": [
{"role": "user", "content": "Explain special relativity."}
],
"reasoning_effort": "medium",
"max_completion_tokens": 2000
}
Pricing verified on November 3, 2026—prices change regularly: before any budget calculation, check the current rate card on the official xAI models and pricing page.
Key points to remember
- Reasoning tokens are in
usage.completion_tokens_details.reasoning_tokens(Chat Completions) orusage.output_tokens_details.reasoning_tokens(Responses) - At xAI,
completion_tokensandoutput_tokenscount only the visible response; the total adds input, response, and reasoning - Reasoning tokens are billed at the output rate
- The output cap limits only the visible response; effort controls reasoning
- The cost difference between efforts depends on the task: measure it on your own data