Skip to content

fix: stop cutting answers short (max_tokens 4096 → 16000) and flag cut-off replies - #4

Merged
dpelezo merged 1 commit into
masterfrom
fix/long-answers
Nov 23, 2026
Merged

dpelezo merged 1 commit into
masterfrom
fix/long-answers

Conversation

@dpelezo

@dpelezo dpelezo commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Summary

Answers stopped mid-sentence. The cause was the app's own output cap, not the model's: max_tokens was 4096, and Claude Haiku 5.5's adaptive thinking counts toward that cap. Long answers and research reports ran out and stopped with stop_reason: "max_tokens", with no sign to the user. The model itself allows up to 128k output tokens.

Changes

  • LLM_MAX_TOKENS default raised from 4096 to 16000. This stays under the Anthropic SDK's ceiling for non-streaming calls (about 21,333 tokens, above which it requires streaming). Checked as accepted for Haiku 5.5, Sonnet 5.5 and Opus 5.5. You pay only for tokens used.
  • A reply or research report that still hits the limit now ends with a short note saying it was cut off.
  • Each model call logs stop_reason and token usage, so cut-offs show up in the Vercel logs.

Verification

  • pytest -q: 40 passed (new tests for cut-off chat replies and reports, and for hit_length_limit)
  • ruff check app tests: passes

Generated by Claude Code

max_tokens was 4096, and adaptive thinking counts toward it, so long
answers and research reports stopped mid-sentence with stop_reason
max_tokens. The default is now 16000, under the Anthropic SDK's
non-streaming ceiling of about 21,333. A reply that still hits the limit
ends with a note, and every model call logs its stop reason and usage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XtW6Y5JF5GNt1txL7PriFg
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ai-assistant-api Ready Ready Preview Nov 23, 2026 8:10pm UTC

@dpelezo
dpelezo merged commit 2416f0c into master Nov 23, 2026
4 checks passed
@dpelezo
dpelezo deleted the fix/long-answers branch November 23, 2026 21:45

This branch was successfully deployed

1 active deployment
Preview — 00b9c510 Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant