Skip to content

[Bug] Custom provider models fail with "maxOutputTokens must be >= 1" when limit is not defined #22253

Closed as not planned

Description

@comzip

Description

After updating to v1.4.3, custom provider models fail with:

Invalid argument for parameter maxOutputTokens: maxOutputTokens must be >= 1

Root Cause

There is an asymmetric fallback between built-in models and custom models (found via binary string analysis):

  • Built-in models: output: limits?.output ?? 64000 → safe fallback to 64000
  • Custom models: output: model.limit?.output ?? existingModel?.limit?.output ?? 0 → falls back to 0, causing the error

When a custom provider model has no limit field defined, maxOutputTokens becomes 0, which is rejected by the AI SDK validation.

Reproduction

Define a custom provider model without a limit field in opencode.json:

"models": {
  "claude-sonnet-4-6": {
    "name": "Claude Sonnet 4.6",
    "type": "chat",
    "available": true
  }
}

Then run opencode with this model — error occurs immediately on any prompt.

Workaround

Add limit to each model in the custom provider config:

"claude-sonnet-4-6": {
  "name": "Claude Sonnet 4.6",
  "type": "chat",
  "available": true,
  "limit": { "context": 200000, "output": 64000 }
}

Expected Behavior

Custom models without a limit field should fall back to a reasonable default (e.g. 64000) instead of 0, consistent with built-in model behavior.

Version

opencode v1.4.3

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 13, 2026
  2. github-actions commented on Apr 13, 2026

    @github-actions
    Contributor

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

    • [BUG] Ollama integration: Invalid maxOutputTokens error #21858: Same error message (maxOutputTokens must be >= 1) with the same root cause — a custom/local provider model without a limit field defined, causing the output tokens to fall back to 0. That issue reports this via Ollama, while this one is via a manually configured custom provider, but they appear to be the same underlying bug.
  3. MertSoylu commented on Apr 13, 2026

    @MertSoylu

    I've fixed this issue! The problem was in provider.ts where custom models without a limit field were falling back to 0 instead of OUTPUT_TOKEN_MAX. Changed the fallback to use ProviderTransform.OUTPUT_TOKEN_MAX (32000), consistent with built-in models.
    PR: #22291

  4. wjiuxing commented on Apr 14, 2026

    @wjiuxing

    @comzip I have also added similar limit information to the model, but I still encounter this problem.
    Image

  5. comzip commented on Apr 15, 2026

    @comzip
    Author

    @wjiuxing I added it to opencode.json as shown below and it works normally.
    "models": { "claude-sonnet-4-6": { "name": "Claude Sonnet 4.6", "type": "chat", "available": true, "limit": { "context": 200000, "output": 64000 } }

  6. wjiuxing commented on Apr 15, 2026

    @wjiuxing

    @wjiuxing I added it to opencode.json as shown below and it works normally. "models": { "claude-sonnet-4-6": { "name": "Claude Sonnet 4.6", "type": "chat", "available": true, "limit": { "context": 200000, "output": 64000 } }

    @comzip Yes. It's working well in a new session but failed in the old interrupted one. Thanks a lot.

  7. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  8. github-actions commented on Jul 5, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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