AIAI Club
← Back to articles
ENGLISH GUIDE

Content Cut Off Midway? Diagnosing and Adjusting FinishReason: MAX_TOKENS

Long code output stops abruptly halfway through? A detailed breakdown of the FinishReason: MAX_TOKENS status code, with guidance on correctly configuring the maxOutputTokens parameter to get complete output.

1. Why Does Content Get Cut Off Midway?

When the returned object's candidates[0].finish_reason shows 2 (that is, MAX_TOKENS), it means the model's response has reached the single-response maximum output limit configured at the time.

2. Three Steps to Adjust the Parameters

1. Check the generation_config dictionary in the call configuration;
2. Explicitly increase max_output_tokens (Gemini 1.5 supports up to 8192 Tokens in a single output);
3. If the task is extremely large and indeed exceeds the 8192 limit, ask the model to output in sections, or send "continue" at the end to initiate an incremental continuation.

This English translation is based on a Chinese source article. Prices are approximate where stated and conditions should be confirmed with the official provider or seller.