Skip to content

Bug: incorrect max_tokens calculation when "thinking" is enabled & "budgetTokens" is set for Anthropic models #2055

Closed

Description

@snipeship

Issue when enabling "thinking" with Anthropic models (Opus in this case):

Tried setting budgetTokens in the opencode.json as follows:

{
  "provider": {
    "anthropic": {
      "models": {
        "claude-opus-4-1-20250805": {
          "options": {
            "thinking": {
              "type": "enabled",
              "budgetTokens": 16000
            }
          }
        }
      }
    }
  }
}

causes this:

AI_APICallError: max_tokens: 48000 > 32000, which is the maximum allowed number of output tokens for claude-opus-4-1-20250805

I have tried to set "maxTokens|max_tokens" within the options, but there seems to (potentially) be a limitation with how the ai-sdk works: https://ai-sdk.dev/providers/ai-sdk-providers/anthropic

That said, it would probably be a good idea to subtract the budgetTokens from the max output tokens hard limit.

Activity

  1. github-actions commented on Aug 19, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. snipeship commented on Aug 19, 2025

    @snipeship
    ContributorAuthor

    It seems like setting:

    [...]
              "limit": {
                "output": 16000
    [...]

    works, but definitely feels like an unnecessary step.

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