Skip to content

models: allow model variants to override limit (context/output) #56582

Open

Description

@dororo42

Summary

Model variants can only carry settings, headers, and body — they cannot override a model's limit (context/output tokens). This makes it impossible to offer multiple context-window tiers (e.g. 256K vs 1M) for the same upstream model without duplicating the whole model entry. Some providers expose this as a first-class control (e.g. the CodeBuddy VS Code extension has a per-model "context length" selector), so an equivalent knob in OpenCode would be useful.

Environment

  • opencode version: 2.0.32
  • OS: Linux 7.0.0-38-generic (Ubuntu, x86_64)
  • Terminal: xterm-256color
  • Shell: /bin/bash
  • Install/channel: latest (release)
  • Active plugins: none found in config

Reproduction

  1. Define a custom openai-compatible model in opencode.jsonc with "limit": { "context": 1000000, "output": 131072 }.
  2. Add variants to the same model entry.
  3. Try to give one variant a smaller context budget (e.g. context: 262144) — the variant schema accepts only settings, headers, and body, so limit cannot be varied.

Expected Behavior

Variant-level limit override (merge order provider → model → variant), so a single catalog entry can expose context tiers:

codebuddy/glm-5.3-flash#1m
codebuddy/glm-5.3-flash#256k

Alternatively, a native per-session context-length selector would achieve the same.

Actual Behavior

limit is static per model entry. The only workaround is duplicating the entry with an alias modelID:

"glm-5.3-flash": {
  "name": "T-GLM-5.3-Flash(快速·1M)",
  "limit": { "context": 1000000, "output": 131072 }
},
"glm-5.3-flash-256k": {
  "modelID": "glm-5.3-flash",
  "name": "T-GLM-5.3-Flash(快速·256K)",
  "limit": { "context": 262144, "output": 131072 }
}

This works, but pollutes the model list with one entry per context tier.

Additional Context

  • Docs (https://opencode.ai/v2/docs/models/) state: "Each variant can contain settings, headers, and body."
  • limit.context is used by OpenCode for context accounting / compaction timing, so a smaller tier genuinely changes behavior, not just display.
  • The motivating setup is a custom openai-compatible provider where the backend serves the same model at different context budgets (CodeBuddy's client picks per request; OpenCode currently can't).

Activity

  1. opencode-agent commented on Oct 17, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed request! You're asking for model variants to be able to override limit (context/output), merged provider → model → variant. That way one model entry could offer context tiers such as codebuddy/glm-5.3-flash#1m and #256k without a duplicate entry for each tier.

    You're right about how it works now: in v2, variants only merge settings, headers and body, and context accounting and compaction always use the base model's limit. A plugin can't do this today either. The plugin provider.models hook can only add whole model entries, which is the same duplication you're trying to avoid. The maintainers will consider this.

    Related issues:

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

Metadata

Metadata

Assignees

No one assigned

    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