Gemini returns empty text with MAX_TOKENS. Raise the output budget or lower thinking
HTTP 200 with empty/truncated text and finishReason MAX_TOKENS means the thinking budget was spent. Raise max_output_tokens or lower thinking_level, then retry. Short answer: 5 steps. 1) Confirm finishReason before you blame the prompt; 2) Check how many tokens went to thoughts vs the answer; 3) Raise max_output_tokens enough for thinking plus the answer; 4) Or lower thinking_level instead of starving the answer; 5) Retest with one short prompt and assert finishReason STOP.
Last updated: · This page is the decision checklist; the tools list for “Fix Gemini empty text with finishReason MAX_TOKENS” is a separate URL.
How do I raise max_output_tokens or lower thinking when Gemini returns empty MAX_TOKENS?
Confirm finishReason before you blame the prompt
Read candidates[0].finishReason (or finish_reason). MAX_TOKENS means generation stopped at your max_output_tokens ceiling—not a safety block and not a 400. Official thinking docs: https://ai.google.dev/gemini-api/docs/thinking
Check how many tokens went to thoughts vs the answer
Log usageMetadata.thoughtsTokenCount (or total_thought_tokens) next to candidatesTokenCount. On thinking models, thought tokens count against max_output_tokens first. Empty text with a high thoughts count is budget exhaustion, not a silent crash.
Raise max_output_tokens enough for thinking plus the answer
max_output_tokens is a hard cutoff on thinking + output combined. A few hundred tokens is often too small at medium/high thinking. Increase the limit, retest the same prompt, and keep it high while you evaluate levels — https://ai.google.dev/gemini-api/docs/thinking
Or lower thinking_level instead of starving the answer
If you need a short reply or low cost, set thinking_level to low or medium (or minimal where supported) rather than capping max_output_tokens tightly. Docs warn a small max_output_tokens can truncate or empty the response while still billing thinking tokens.
Retest with one short prompt and assert finishReason STOP
Call again with a tiny question, a higher max_output_tokens, and a known thinking_level. Expect STOP (or a completed interaction) and non-empty text. If you still see MAX_TOKENS with empty text, raise the budget further or drop the thinking level before changing the prompt.
Which tools are best to fix Gemini empty text with finishReason MAX_TOKENS?
Gemini thinking guide
Documents that max_output_tokens includes thought tokens and can empty or truncate the answer.
Gemini generateContent reference
finishReason MAX_TOKENS and candidate fields for diagnosing empty replies.
Token counting
How Gemini counts tokens so you can size max_output_tokens.
Google AI Studio
Reproduce the same model, thinking_level, and max_output_tokens before changing production code.
Open: 1 spot per week
One labeled sponsor for this topic each week; this week's spot is open. See open weeks →
All tools for “Fix Gemini empty text with finishReason MAX_TOKENS” →
Related fixes
- Stop a Cursor agent loopHow to fix a Cursor agent loop (same edit, or work after Stop)Fix →
- Claude Code vs Codex vs Cursor ~$20 plansClaude Code vs Codex vs Cursor $20 plan limits: how to pick without burning the weekFix →
- Scan a vibe-coded app for leaked API keysCheck a vibe-coded app for leaked API keys before you share itFix →
- Add an MCP server to Claude Code, Cursor, or CodexHow to add an MCP server to Claude Code, Cursor, or CodexFix →
See also AI tools launched today on the daily board.
NewAIToolsToday Daily
Top 3 AI launches, one model or news item that matters, and one simple fix. A 5-minute read, every weekday.