Skip to content

Getting maxOutputTokens error when sending a message (0.2.26+) #858

Closed

Description

@svkozak

After upating to 0.2.26+ getting this error when trying to send a message:

ERROR 2025-07-10T20:54:23 +0ms service=tui failed to send message: POST "http://127.0.0.1:64603/session/ses_809e2202cffe2wWGTu1lEcRRjD/message": 400 Bad Request {"name":"UnknownError","data":{"message":"AI_InvalidArgumentError: Invalid argument for parameter maxOutputTokens: maxOutputTokens must be >= 1"}}

Using Claude Sonnet 4 via @ai-sdk/openai-compatible proxy

Activity

  1. ggaabe commented on Jul 10, 2025

    @ggaabe
    Contributor

    I'm getting the same trying to point it at a locally running r1 model hosted via LM Studio:

    Image
  2. svkozak commented on Jul 10, 2025

    @svkozak
    ContributorAuthor

    Workaround to restore functionality: add the params in ~/.config/opencode/config.json:

    In my case it was "claude-sonnet-4": {}, I added limit:

          "models": {
            "claude-sonnet-4": {
              "limit": {
                "context": 200000,
                "output": 32000
              }
            }
          }
  3. svkozak commented on Jul 10, 2025

    @svkozak
    ContributorAuthor

    Opened this #860 to fall back to OUTPUT_TOKEN_MAX when limit is undefined

  4. skelz0r commented on Jul 11, 2025

    @skelz0r

    I tried the workaround but I have the following issues:

    opencode.log

    ERROR 2025-07-11T07:09:51 +1ms service=session session=ses_807ae54e0ffeKLY96BvnvIFKW7 error=The number of tokens to keep from the initial prompt is greater than the context length.
    ERROR 2025-07-11T07:09:51 +0ms service=tui failed to send message: POST "http://127.0.0.1:56548/session/ses_807ae54e0ffeKLY96BvnvIFKW7/message": 400 Bad Request {"name":"UnknownError","data":{"message":"TypeError: J is not an Object. (evaluating '\"name\"in J')"}}
    

    LMStudio log

     The number of tokens to keep from the initial prompt is greater than the context length.. Error Data: n/a, Additional Data: n/a
    

    I'm using LMStudio with mistralai/devstral-small-2507, tried a bunch of context/output, same error.
    Any clue?

    Edit: same with other local models.

  5. bmorton commented on Jul 11, 2025

    @bmorton

    I'm seeing the same as what @skelz0r sees. Edit: same setup -- LMStudio, devstral.

  6. bmorton commented on Jul 11, 2025

    @bmorton

    Actually, this fixes it with Ollama for me. LMStudio still has the same result as @skelz0r.

  7. mchzimm commented on Jul 11, 2025

    @mchzimm

    FYI opencode v0.2.21 was the last ver that worked for me

    as per @bmorton last comment, unfortunately ollama isn't a solution for everyone (including myself) as it doesn't run accelerated on my system, LMS does though via vulkan.

  8. bazhand commented on Jul 11, 2025

    @bazhand

    { "$schema": "https://opencode.ai/config.json", "theme": "opencode", "model": "anthropic/claude-3.5-sonnet", "autoshare": false, "autoupdate": true, "provider": { "ollama": { "npm": "@ai-sdk/openai-compatible", "name": "Ollama (local)", "options": { "baseURL": "http://localhost:11434/v1", "apiKey": "ollama" }, "models": { "llama3.2:latest": { "name": "Llama 3.2", "limit": { "context": 128000, "output": 4096 } }, "mistral:7b": { "name": "Mistral 7B", "limit": { "context": 32768, "output": 4096 } }, "deepseek-r1:8b": { "name": "DeepSeek R1 8B", "limit": { "context": 32768, "output": 4096 } } } } } }

    works for me using local llm with Ollama

  9. self-assigned this
    on Jul 12, 2025
  10. thdxr commented on Jul 12, 2025

    @thdxr
    Member

    fixed in 0.2.28

  11. codeus42 commented on Aug 20, 2025

    @codeus42

    This problem still exists with LM Studio. It needs to manually increase the context inside LM Studio

    Image
  12. added a commit that references this issue on Apr 7, 2026
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