Skip to content

AI_APICallError with Qwen 3 Coder 480b: Please reduce the length of the messages or completion. Current length is 69553 while limit is 65536 #1551

Closed

Description

@adeperio

I am getting the following error:

Image

It goes through a number of tool calls like fetch, and glob, and task and then errors out with that message. Here's the prompt I'm using for reference if it helps recreate the issue:

_I have now downloaded opencode from https://opencode.ai/docs/. I'm trying to set it up and reading the config docs at https://opencode.ai/docs/config/#modes

Can you read through all the docs. I want to learn how to setup MCP servers for me in open code using the opencode.json file. Is there a way to also leverage my existing @CLAUDE.md files in my repo subfolder to help setup opencode?

Before you do anything can you provide me with an over view of what I can do to set things up?_

Activity

  1. changed the title [-]AI_APICallError with Qwen 3 Code 480b: Please reduce the length of the messages or completion. Current length is 69553 while limit is 65536[/-] [+]AI_APICallError with Qwen 3 Coder 480b: Please reduce the length of the messages or completion. Current length is 69553 while limit is 65536[/+] on Aug 3, 2025
  2. adeperio commented on Aug 3, 2025

    @adeperio
    Author

    It looks like it's hitting max content length for the model and not compacting down the chat history when it reaches the limit.

  3. adeperio commented on Aug 3, 2025

    @adeperio
    Author

    Interestingly I also get this error when trying to find the bug in the opencode repo, with opencode. Probably another github issue though :)

    Image

    Debugging with claude code the error: "AI_APICallError: Please reduce the length of the messages or completion" I get the following:

    Summary

    The issue is in /packages/opencode/src/session/index.ts around
    lines 612-624. The context length check before summarization is
    insufficient because:

    1. It only checks the previous assistant message's token count
    2. It doesn't account for the total tokens that will be sent to
      the model, including:
      - System prompts
      - All conversation messages
      - The new user message

    When the total exceeds 65536 tokens (Cerebras' limit), the API
    throws the error before summarization can help.

    Fix

    The context check needs to estimate the total tokens that will
    be sent. Here's what needs to be changed:

    1. Calculate total tokens including system prompts and all
      messages
    2. Trigger summarization when approaching the limit
    3. Consider implementing a more aggressive summarization
      strategy for models with smaller context windows

    The check should happen before line 822 where streamText is
    called, and should account for all the messages that will be
    sent in the messages array.

  4. self-assigned this
    on Aug 3, 2025
  5. thdxr commented on Aug 3, 2025

    @thdxr
    Member

    what provider are you using where the limit is this low?

  6. adeperio commented on Aug 4, 2025

    @adeperio
    Author

    Hi @thdxr it's with Cerebras.

  7. polo871209 commented on Aug 8, 2025

    @polo871209

    I am facing the similiar issue using copilot/gpt-5 now 🙏

    AI_APICallError: prompt token count of 128783 exceeds the limit of 128000

  8. torbjornvatn commented on Aug 13, 2025

    @torbjornvatn

    I am facing the similiar issue using copilot/gpt-5 now 🙏

    AI_APICallError: prompt token count of 128783 exceeds the limit of 128000

    Same here. Is this a limit set by copilot somehow?

  9. jflaflamme commented on Aug 24, 2025

    @jflaflamme

    I got this error just now but what's concerning is the output after was someone's request about django and cloudflare which was totally unrelated to my context and query.

    Image
  10. rekram1-node commented on Aug 24, 2025

    @rekram1-node
    Contributor

    @jflaflamme thats very strange… just for clarity it is literally impossible for “someone elses request” to be sent instead of yours (on our end) because the opencode instance is only running on your machine, I guess technically anthropic could have served you the wrong response somehow but I feel like this is the llm confusing itself based on context and other things most likely

  11. jflaflamme commented on Aug 25, 2025

    @jflaflamme

    @jflaflamme thats very strange… just for clarity it is literally impossible for “someone elses request” to be sent instead of yours (on our end) because the opencode instance is only running on your machine, I guess technically anthropic could have served you the wrong response somehow but I feel like this is the llm confusing itself based on context and other things most likely

    I appreciate the prompt response and I didn't mean to hijack the topic, just the the AI_APICallError about the length of the message error was the same even with Anthropic models selected, perhaps because of the context? Weird too.

    Same goes for the possible confusing context, which I never had issues with before with Claude code (or opencode).
    Could it be because I switched the model used for the agent within the session?

  12. rekram1-node commented on Aug 25, 2025

    @rekram1-node
    Contributor

    tbh I am not really sure without seeing your session, as for the error we need to do more context optimizations like:

    • better compact
    • limit tool outputs
    • etc
  13. adeperio commented on Aug 25, 2025

    @adeperio
    Author

    Thanks all for your comments. Just tried Qwen on Cerebras again today to see if I can get it working, but I still keep running into this same issue. I don't get this issue with the anthropic or open AI models. Qwen unfortunately for me is un-useable atm. Let me know if there's other ways I can get more info to help debug this one and I'll see if I can get everyone some more detail. Thanks!

  14. rekram1-node commented on Dec 28, 2025

    @rekram1-node
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions