cd /news/large-language-models/gemini-api-returns-empty-text-with-f… · home › topics › large-language-models › article
[ARTICLE · art-174210] src=dev.to ↗ pub= topic=large-language-models verified=true sentiment=↓ negative

Gemini API returns empty text with finishReason MAX_TOKENS: thinking tokens use the limit first

A developer reproduced a silent failure in the Gemini API where thinking tokens consume the max_output_tokens budget before any answer text is generated, returning HTTP 200 with an empty string and finishReason MAX_TOKENS. In a 10 November 2026 test with one arithmetic prompt, gemini-3.6-flash at high thinking spent 57 thought tokens and produced zero characters at a 60-token limit, while gemini-3-flash-preview used 21,607 thinking tokens at high with no limit set. The developer recommends checking candidates[0].finish_reason before reading text and comparing thoughts_token_count against candidates_token_count to diagnose where the budget went.

recommendation

Check candidates[0].finish_reason and compare thoughts_token_count with candidates_token_count before reading text, and set output limits well above a few hundred tokens on thinking models.

more in playbook: Controlling LLM cost
by read2 min views2 publishedNov 22, 2026

On Gemini models that think, the tokens spent on reasoning count against max_output_tokens before the first word of the answer is written. The failure is quiet: no exception, HTTP 200, and a response whose text is an empty string.

I reproduced it on purpose on 10 November 2026 with one arithmetic question (a train problem with a known answer, 11:49, asked for in one sentence, so a correct reply is about 15 tokens) and a ladder of output limits, recording the token counts the API reports. Everything below is from that run with one free-tier key.

from google import genai
from google.genai import types

client = genai.Client()

def run(model, level, max_tokens=None):
    cfg = types.GenerateContentConfig(
        thinking_config=types.ThinkingConfig(thinking_level=level),
        max_output_tokens=max_tokens,
    )
    r = client.models.generate_content(model=model, contents=PROMPT, config=cfg)
    u = r.usage_metadata
    return {
        "finish": r.candidates[0].finish_reason,
        "text_chars": len(r.text or ""),
        "thoughts": u.thoughts_token_count,
        "answer_tokens": u.candidates_token_count,
    }

run("gemini-3.6-flash", "high", 60) returned MAX_TOKENS, zero characters of text, 57 thought tokens and 0 answer tokens. The usage fields are the diagnosis: thoughts_token_count next to candidates_token_count shows where the budget went.

At a limit of 60, gemini-3-flash-preview spent 56 tokens on thoughts and returned an empty string. gemini-3.5-flash-lite spent 53 on thoughts and returned 3 answer tokens, the words "They will meet". All ended with MAX_TOKENS, but only some gave an empty string to notice; the others gave a fragment that looks like text.

On gemini-3.6-flash at high thinking, thinking took almost the whole allowance every time:

A truncated reply is worse than an empty one for a pipeline, because that cut-off text passes an if text: check.

Without any limit, gemini-3-flash-preview used 21,607 thinking tokens at high and 1,325 at low for the same question. A limit of a few hundred is far too small for a thinking model, and 4,000 was still not enough at high on that model: the answer came back cut off after 160 tokens.

Lowering the level is not free either: gemini-3.5-flash-lite at low used 0 thinking tokens and answered 12:00 PM, where the right answer is 11:49.

candidates[0].finish_reason before you read text; an empty text together with MAX_TOKENS means the budget was spent on thinking.thoughts_token_count and candidates_token_count together. One question, one free-tier key, one day. Some models hit their daily free quota during the work, which is why the results mix models. Model behaviour and limits change, so run the probe on your own setup.

More detail and the FAQ: https://aiandsoftwarehub.com/blog/gemini-api-returns-empty-text-with-finishreason-max-tokens-thinking-tokens-eat-y

── more in #large-language-models 4 stories · sorted by recency
── more on @google 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/gemini-api-returns-e…] indexed:0 read:2min 2026-11-22 · —