The answer that stopped mid-sentence
Short answers in your study app are fine. Long ones end mid-sentence, like this: 'The third cause of the war was the'
This answers: Why does my AI response get cut off? No coding needed. 3 quick decisions.
- Debugging without panic
- Costs and abuse
Checking your access…
Why does my AI response get cut off?
The model reached the maximum output tokens set in your request and was stopped. The response says so: finish_reason is 'length' at OpenAI, stop_reason is 'max_tokens' at Anthropic. Set a limit that fits the answers you want, check the stop reason on every reply, and continue or warn the user when it was cut off.
Breaks at Your server: Stop reason never checked
Why AI tools write this bug
Generated code usually sets a small max_tokens value from an example and reads only the text, never the stop reason.
How to fix it
- Log the stop reason with every AI reply.
- Raise the output limit to fit real answers.
- Continue or flag replies that were cut off.
- Check the stop reason before parsing JSON.
Check your own app
Paste this into Lovable, Cursor or Claude Code:
Without changing anything, list every AI call in this project, the output token limit each one sets, and whether the code checks the finish or stop reason. What does the user see if a reply is cut off?
Common questions
- Should I remove max_tokens completely?
- No. It caps the cost of a single reply. Keep a sensible limit and handle hitting it.