Submit a toolSubmit

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.

The problem: 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.

How do I raise max_output_tokens or lower thinking when Gemini returns empty MAX_TOKENS?

  1. 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

  2. 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.

  3. 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

  4. 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.

  5. 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.

All tools for “Fix Gemini empty text with finishReason MAX_TOKENS” →

Related fixes

See also AI tools launched today on the daily board.