AI_APICallError ... exceed context limit when tool call returns long document #1244

Closed
opened 2026-02-16 17:30:09 -05:00 by yindo · 6 comments
Owner

Originally created by @taxilian on GitHub (Aug 11, 2025).

Originally assigned to: @thdxr on GitHub.

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

I see a message like this very frequently, generally seems to happen when a tool call has a particularly long return, such as a grep or a make test. This has gotten to be a very common problem with several projects I've been using it with, particularly because it doesn't seem to recover from it well.

Seems like opencode could detect if the output from the tool is too big for context and put it in a file to let the agent process it that way, or ...? dunno. brainstorming. y'all know your project better than I =]

Awesome tool, keep up the good work!

Originally created by @taxilian on GitHub (Aug 11, 2025). Originally assigned to: @thdxr on GitHub. ``` AI_APICallError: input length and `max_tokens` exceed context limit: 173088 + 32000 > 200000, decrease input length or `max_tokens` and try again ``` I see a message like this *very* frequently, generally seems to happen when a tool call has a particularly long return, such as a `grep` or a `make test`. This has gotten to be a very common problem with several projects I've been using it with, particularly because it doesn't seem to recover from it well. Seems like opencode could detect if the output from the tool is too big for context and put it in a file to let the agent process it that way, or ...? dunno. brainstorming. y'all know your project better than I =] Awesome tool, keep up the good work!
yindo closed this issue 2026-02-16 17:30:09 -05:00
Author
Owner

@thdxr commented on GitHub (Aug 11, 2025):

we do try to limit grep command - an example would help!

@thdxr commented on GitHub (Aug 11, 2025): we do try to limit grep command - an example would help!
Author
Owner

@taxilian commented on GitHub (Aug 12, 2025):

it seems to be literally any command it runs that has a really long output; make test is doing it a lot in my current system, where make test runs unit tests for a golang project and has a long output. I've seen it on a typescript project as well and I think it was when running unit tests, probably using pnpm test

@taxilian commented on GitHub (Aug 12, 2025): it seems to be literally any command it runs that has a really long output; `make test` is doing it a lot in my current system, where `make test` runs unit tests for a golang project and has a long output. I've seen it on a typescript project as well and I think it was when running unit tests, probably using `pnpm test`
Author
Owner

@taxilian commented on GitHub (Aug 12, 2025):

https://opencode.ai/s/Jg9xc9Eg is my most recent case; it doesn't capture or show the errors in there, but you can see how long the output of "make test" is.

That might be something to fix as well, add the errors into the share?

Image

I do have instructions in agents.txt to always pipe the output of tests to a file, but it forgets sometimes. either way it seems like opencode should be able to somehow detect and work around this

@taxilian commented on GitHub (Aug 12, 2025): https://opencode.ai/s/Jg9xc9Eg is my most recent case; it doesn't capture or show the errors in there, but you can see how long the output of "make test" is. That might be something to fix as well, add the errors into the share? <img width="876" height="457" alt="Image" src="https://github.com/user-attachments/assets/006ac6ee-0d05-483e-a390-8a27dfca77aa" /> I do have instructions in agents.txt to always pipe the output of tests to a file, but it forgets sometimes. either way it seems like opencode should be able to somehow detect and work around this
Author
Owner

@thdxr commented on GitHub (Aug 12, 2025):

gotcha the bash command might not be limiting let me see

@thdxr commented on GitHub (Aug 12, 2025): gotcha the bash command might not be limiting let me see
Author
Owner

@thdxr commented on GitHub (Aug 12, 2025):

just added 1000 line limit, closing for now feel free to make new issues if you have more specific problems

@thdxr commented on GitHub (Aug 12, 2025): just added 1000 line limit, closing for now feel free to make new issues if you have more specific problems
Author
Owner

@taxilian commented on GitHub (Aug 12, 2025):

that should help =] I'm on Discord btw if you have questions there while I'm around.

I wondered if it might be better to have a way to have it detect if it's too long and output to a file, then instead of giving the results report the file where it was saved. just a brainstorm thought.

this does at least keep it from getting totally stuck, I think =] thanks!

@taxilian commented on GitHub (Aug 12, 2025): that should help =] I'm on Discord btw if you have questions there while I'm around. I wondered if it might be better to have a way to have it detect if it's too long and output to a file, then instead of giving the results report the file where it was saved. just a brainstorm thought. this does at least keep it from getting totally stuck, I think =] thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#1244