Billing and cost optimization
On this page
Updated November 3, 2026: Previous examples accessed
usage.prompt_tokensandusage.completion_tokenson Responses API responses, which exposeinput_tokens,output_tokens, and their details (cached_tokens,reasoning_tokens): the code raisedAttributeError. Cost tracking now accounts for cached input, and the advice to lower the output limit to limit reasoning is corrected, as this limit does not count reasoning. Sources: Models and Pricing · Best practices.
Reasoning tokens on your bill
Billing for reasoning tokens is a critical aspect of using xAI models. These tokens are billed at the output token rate—the highest rate—and unoptimized usage can quickly drive up costs, especially with high reasoning effort on grok-4.5.
New for 2026 and important to understand: pricing is tiered. The price per token depends on the request context size. Under 200k prompt tokens, you pay the standard rate; above that, the rate doubles.
Pricing by model (July 2026)
Price per million tokens.
| Model | Input < 200k | Output < 200k | Input ≥ 200k | Output ≥ 200k |
|---|---|---|---|---|
| grok-4.5 | $2.00 | $6.00 | $4.00 | $12.00 |
| grok-4.20-0309-reasoning | $1.25 | $2.50 | $2.50 | $5.00 |
| grok-4.3 | $1.25 | $2.50 | $2.50 | $5.00 |
| grok-build-0.1 | $1.00 | $2.00 | $2.00 | $4.00 |
Reasoning tokens are billed at the “Output” column rate. With grok-4.5 under 200k context, every million reasoning tokens costs $6.00; with grok-4.20-0309-reasoning, $2.50. And if your prompt exceeds 200k tokens, these amounts double: $12.00 and $5.00.
Track the cost of each request
The usage object in the response contains token counters; some xAI API responses may also include direct cost fields. Inspect the usage object returned by your model and check the official documentation for available fields. Otherwise, manual calculation is straightforward:
response = client.responses.create(
model="grok-4.5",
input="Solve this dynamic programming problem...",
reasoning={"effort": "high"}
)
# grok-4.5 rates under 200k context tokens (Responses API counts in input/output)
usage = response.usage
input_cost = usage.input_tokens * 2.00 / 1_000_000
output_cost = usage.output_tokens * 6.00 / 1_000_000 # includes reasoning
total_cost = input_cost + output_cost
print(f"Input cost: ${input_cost:.6f}")
print(f"Output cost: ${output_cost:.6f}")
print(f"Total cost: ${total_cost:.6f}")
Caution: this calculation assumes a context under 200k tokens. In production, your tracker must detect the applicable tier (see below).
Cost optimization strategies
1. Match effort to the task
The first and most effective optimization is to choose the right reasoning effort level on grok-4.5. Low effort can consume significantly fewer reasoning tokens than high effort:
# Sort requests by complexity
if complexity == "simple":
effort = "low" # brief reasoning
elif complexity == "medium":
effort = "medium" # intermediate reasoning
else:
effort = "high" # deep reasoning
Check the exact values accepted by the parameter on the official models page.
2. Use the right model
For common reasoning tasks, grok-4.20-0309-reasoning at $2.50/M output costs less than half of grok-4.5 at $6.00/M. Reserve the flagship model for tasks that truly require it. For code, grok-build-0.1 at $2.00/M output is even more economical.
3. Stay under the 200k token tier
The pricing tier is a direct lever: a request with 250k context tokens costs twice as much per token as a request with 150k. Before sending a massive context, ask yourself if splitting it into several smaller requests (or an intermediate summary) wouldn’t be both cheaper and more effective.
4. Leverage prompt caching
xAI offers reduced pricing for input tokens already in cache: repeated prompt prefixes (system instructions, shared context) cost less when reused from one request to the next. Under 200k tokens, cached input costs $0.30 per million instead of $2.00 with grok-4.5, and $0.20 instead of $1.25 with grok-4.20-0309-reasoning (Models and Pricing page, November 2026). Structure your prompts with stable parts at the head; the portion served by cache appears in usage.input_tokens_details.cached_tokens.
5. Size the output limit
The output limit (max_output_tokens in the Responses API, max_completion_tokens in Chat Completions) limits only the visible response: reasoning tokens do not count toward it. Lowering it therefore does not reduce reasoning; it risks cutting off the response only. xAI best practices recommend setting it above the longest expected response, or leaving its default value of 128,000 tokens. To reduce reasoning, lower the effort on models that accept it, or choose a cheaper model.
Budget tracking in production
class CostTracker:
# Rates per MTok: (input, cached input, output) by context tier
RATES = {
"grok-4.5": {"low": (2.00, 0.30, 6.00), "high": (4.00, 0.60, 12.00)},
"grok-4.20-0309-reasoning": {"low": (1.25, 0.20, 2.50), "high": (2.50, 0.40, 5.00)},
"grok-build-0.1": {"low": (1.00, 0.20, 2.00), "high": (2.00, 0.40, 4.00)},
}
TIER_THRESHOLD = 200_000 # prompt tokens
def __init__(self):
self.total_cost = 0
self.request_count = 0
def track(self, response, model="grok-4.5"):
usage = response.usage # Responses API response
details = usage.input_tokens_details
cached = details.cached_tokens if details else 0
tier = "high" if usage.input_tokens >= self.TIER_THRESHOLD else "low"
rate_in, rate_cached, rate_out = self.RATES[model][tier]
cost = (
(usage.input_tokens - cached) * rate_in / 1e6
+ cached * rate_cached / 1e6
+ usage.output_tokens * rate_out / 1e6 # includes reasoning
)
self.total_cost += cost
self.request_count += 1
return cost
Pricing as of August 5, 2026 — prices change regularly: before any budget calculation, verify the current grid on the official xAI models and pricing page.
Key takeaways
- Reasoning tokens are billed at the output token rate
- 2026 pricing is tiered: beyond 200k context tokens, the price per token doubles
- grok-4.5 costs $2/$6 per MTok under 200k ($4/$12 above); grok-4.20-0309-reasoning costs $1.25/$2.50 ($2.50/$5 above)
- The three main levers: match reasoning effort, choose the right model, stay under the 200k tier
- Track your costs request by request, accounting for the applicable tier