Fetched documentation exeeds context window limit - Automatic truncation possible? #855

Closed
opened 2026-02-16 17:28:34 -05:00 by yindo · 2 comments
Owner

Originally created by @WismutHansen on GitHub (Jul 22, 2025).

Originally assigned to: @thdxr on GitHub.

When opencode pulls documentation from websites, the resulting response can sometimes exceed the context length of the current model in use (currently Claude sonnet 4 for me). It's impossible to continue this sessions in this case. Manually editing the sessions logs and removing the content makes it possible to resume the session.

Could we implement a token counter that considers how many tokens are left in a given session and truncates the fetched content to a size that still fits the context window (including a short hint for the model)?

Here is the error message for reference:

AI_APICallError: input length and max_tokens exceed context limit: 184714 + 32000 > 200000, decrease input length or max_tokens and try again

Originally created by @WismutHansen on GitHub (Jul 22, 2025). Originally assigned to: @thdxr on GitHub. When opencode pulls documentation from websites, the resulting response can sometimes exceed the context length of the current model in use (currently Claude sonnet 4 for me). It's impossible to continue this sessions in this case. Manually editing the sessions logs and removing the content makes it possible to resume the session. Could we implement a token counter that considers how many tokens are left in a given session and truncates the fetched content to a size that still fits the context window (including a short hint for the model)? Here is the error message for reference: AI_APICallError: input length and `max_tokens` exceed context limit: 184714 + 32000 > 200000, decrease input length or `max_tokens` and try again
yindo closed this issue 2026-02-16 17:28:34 -05:00
Author
Owner

@isaacraja commented on GitHub (Jul 25, 2025):

I see a similiar error message on retrieving from docs from web. AI_APICallError: input length and max_tokens exceed context limit: 190641 + 32000 > 200000, decrease input length or max_tokens and try again

@isaacraja commented on GitHub (Jul 25, 2025): I see a similiar error message on retrieving from docs from web. AI_APICallError: input length and `max_tokens` exceed context limit: 190641 + 32000 > 200000, decrease input length or `max_tokens` and try again
Author
Owner

@rekram1-node commented on GitHub (Dec 27, 2025):

[automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!

@rekram1-node commented on GitHub (Dec 27, 2025): [automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#855