Gemini Thinking Budgets: Configure Reasoning Effort and Token Caps
Control Gemini thinking budgets and reasoning levels in production by separating visible output tokens from internal reasoning tokens and capping retries.

Reasoning-capable Gemini models generate internal thought tokens before emitting user-visible text. If your application enables maximum reasoning effort on every turn without an explicit thinking budget, internal reasoning tokens can inflate time-to-first-token (TTFT), exhaust output token allowances, and turn routine traffic spikes into 429 RESOURCE_EXHAUSTED incidents.
Review Google's Gemini thinking documentation and pricing guide for model-specific reasoning controls, and check the API429 documentation and model catalog to verify which models and request parameters are supported on your gateway route.
How Gemini thinking tokens affect latency, truncation, and billing
In Google's Gemini API, thinking models reason internally before producing the visible response. Depending on the exact model generation (such as Gemini 2.5 and Gemini 3 series models), Google documents controls under thinkingConfig—including integer thinkingBudget token caps or discrete thinkingLevel settings—and reports reasoning token consumption in usage metadata (such as thoughtsTokenCount).
Three accounting rules apply to every reasoning workload:
- Thinking tokens are billed as output tokens: Internal reasoning tokens are generated by the model and count toward output token charges, even when raw thought summaries are not displayed to end users.
- Thinking tokens share output and deadline ceilings: If a request sets a small total output cap while the model spends most of that allowance on internal reasoning, the visible completion can truncate mid-sentence or mid-JSON object (
finish_reason = "length"), breaking downstream parsers. - Gateway parameter support must be verified per route: When calling an OpenAI-compatible endpoint (
POST /v1/chat/completions), verify whetherreasoning_effortor provider-specific thinking fields are accepted for the target model ID in the API429 API reference, rather than assuming nativethinkingConfigfields pass through unchanged.
Decision table: match reasoning effort to workload class
Assign an explicit reasoning tier per task type in your application router instead of defaulting every endpoint to maximum thinking:
| Workload class | Recommended thinking tier | Output & deadline policy | Fallback / retry rule |
|---|---|---|---|
| Simple classification, routing, or field formatting | Off or minimal (0–256 tokens where supported) |
Tight max_tokens and short TTFT deadline |
Fast non-reasoning or Flash-Lite model |
| Customer chat, summarization, or grounded Q&A | Low to medium (512–2,048 thinking tokens) |
Reserve output headroom for both thoughts and visible answer | Do not escalate thinking budget on HTTP 429 |
| Structured JSON extraction with complex rules | Bounded medium (1,024–2,048 tokens) + schema check |
Ensure max_tokens covers thinking budget + full JSON schema size |
Use structured-output pipeline rules |
| Deep code review, math proof, or multi-step planning | High (4,096–16,384+ tokens) on asynchronous queue |
Run via queue admission with extended deadline | Never run unthrottled retries on high-thinking jobs |
Prevent truncation and retry amplification on reasoning calls
When a high-thinking call fails or truncates, naive retry logic causes two severe failure modes:
- Truncation loops on structured outputs: If
max_output_tokensis set to2,048and the model spends1,900tokens thinking, only148tokens remain for the JSON body. The response truncates, failsjson.loads, and triggers a futile retry. Always size the total output cap asthinking_budget_tokens + required_visible_output_tokens. - Quota multiplication during 429 incidents: Under Google Gemini API rate limits and RFC 6585 Section 4, retrying a slow, heavy reasoning request immediately wastes both concurrency slots and token budgets. Route all 429 responses through the application retry budget policy and reserve worst-case cost (input + thinking budget + visible output) using the cost guardrails guide.
Runnable offline Python thinking-budget planner and usage reconciler
The standalone Python module below computes safe total output token ceilings that accommodate both the thinking budget and the required visible output, reserves worst-case cost before dispatch, and reconciles actual visible versus thinking token usage:
from dataclasses import dataclass
@dataclass(frozen=True)
class ThinkingPlan:
admitted: bool
reason: str
thinking_budget_tokens: int
visible_output_reserve: int
total_max_output_tokens: int
reserved_cost_usd: float
def plan_thinking_request(
*,
task_tier: str,
estimated_input_tokens: int,
visible_output_reserve: int,
model_max_output_limit: int,
input_rate_per_1m: float,
output_rate_per_1m: float,
max_task_cost_usd: float,
) -> ThinkingPlan:
tier_budgets = {
"minimal": 0,
"low": 512,
"medium": 2048,
"high": 8192,
}
if task_tier not in tier_budgets:
return ThinkingPlan(False, "unknown_task_tier", 0, 0, 0, 0.0)
thinking_tokens = tier_budgets[task_tier]
total_output_cap = thinking_tokens + visible_output_reserve
if total_output_cap > model_max_output_limit:
return ThinkingPlan(
False,
"thinking_plus_visible_exceeds_model_output_limit",
thinking_tokens,
visible_output_reserve,
total_output_cap,
0.0,
)
reserved_usd = round(
(estimated_input_tokens / 1_000_000) * input_rate_per_1m
+ (total_output_cap / 1_000_000) * output_rate_per_1m,
6,
)
if reserved_usd > max_task_cost_usd:
return ThinkingPlan(
False,
"exceeds_max_task_cost_usd",
thinking_tokens,
visible_output_reserve,
total_output_cap,
reserved_usd,
)
return ThinkingPlan(
True,
"admitted",
thinking_tokens,
visible_output_reserve,
total_output_cap,
reserved_usd,
)
def reconcile_thinking_usage(usage: dict, output_rate_per_1m: float) -> dict:
visible_out = int(usage.get("candidates_token_count", usage.get("completion_tokens", 0)))
thoughts_out = int(usage.get("thoughts_token_count", 0))
total_billed_out = visible_out + thoughts_out
thought_share = round(thoughts_out / max(1, total_billed_out), 4)
output_cost_usd = round((total_billed_out / 1_000_000) * output_rate_per_1m, 6)
return {
"visible_output_tokens": visible_out,
"thinking_tokens": thoughts_out,
"total_billed_output_tokens": total_billed_out,
"thinking_share_ratio": thought_share,
"billed_output_cost_usd": output_cost_usd,
}
if __name__ == "__main__":
plan = plan_thinking_request(
task_tier="medium",
estimated_input_tokens=6_000,
visible_output_reserve=1_500,
model_max_output_limit=64_000,
input_rate_per_1m=1.25,
output_rate_per_1m=5.00,
max_task_cost_usd=0.05,
)
summary = reconcile_thinking_usage(
{"candidates_token_count": 920, "thoughts_token_count": 1840},
output_rate_per_1m=5.00,
)
print("Thinking plan:", plan)
print("Reconciled usage:", summary)
Log reasoning telemetry and compare model tiers
Track thinking_budget_tokens, observed thoughts_token_count (when exposed by the endpoint), visible completion tokens, TTFT, total latency, and finish_reason across your routes. Use the Gemini token counting guide to reconcile pre-call estimates against post-call bills, and review the Google provider hub, pricing comparison, API429 pricing, and FAQ when choosing between reasoning-heavy Pro models and low-latency Flash or Flash-Lite models.
FAQ
Are Gemini thinking tokens charged at the input rate or the output rate?
Google bills internal thinking tokens as output tokens generated by the model. Always include your configured thinkingBudget inside your pre-call output cost reservation.
Why did my structured JSON response truncate even though the JSON object is only 300 tokens?
If max_output_tokens (or max_tokens) was set to 1,000 and the model spent 850 tokens on internal thinking, only 150 tokens remained for the visible JSON output. Set the total output limit to cover both the thinking budget and the expected JSON payload size.
Should a worker increase the thinking budget when a request fails with HTTP 429?
No. HTTP 429 is a rate-limit or capacity signal, not a reasoning-quality failure. Increasing reasoning effort during a 429 incident burns more tokens and worsens queue congestion.
Do all OpenAI-compatible gateway routes expose thoughtsTokenCount?
Not always. Field names and parameter pass-through depend on the endpoint contract. Inspect the API429 public OpenAPI specification and test a representative call with your key to verify which usage fields are returned.
When should a reasoning workload fall back to a non-thinking or lower-tier model?
Only when the downstream task contract permits a lower-reasoning tier (such as summarizing already-extracted facts or handling routine chat turns) and the fallback model has passed your acceptance suite. Never silently downgrade a complex verification or structured extraction job without checking output quality.
Sources & further reading
Put the next step into practice.
Check model IDs, current pricing and request formats before integrating. Availability can depend on the model and provider route.

