Skip to content

OpenAI-compatible providers without /v1/models endpoint fall back to hardcoded 200k context limit with no override #262

Closed

Description

@mmacedoeu

When using an OpenAI-compatible provider that doesn't expose a GET /v1/models endpoint (e.g. a custom proxy/gateway), the context window
resolution chain has no way to discover the actual context_length for models.

Resolution chain observed:

  1. openai_compatible_profile_context_limit() — only has a hardcoded entry for DeepSeek V4; returns None for other models
  2. GET {api_base}/models — returns 404 on providers that don't support it
  3. CONTEXT_LIMIT_CACHE — empty (nothing to populate from)
  4. Falls back to DEFAULT_CONTEXT_LIMIT = 200,000

This means models with larger context windows (e.g. mimo-v2.5-pro which may support 128k+) are incorrectly limited, and models with smaller
windows waste budget on requests that will fail.

Steps to reproduce:

  1. Configure an OpenAI-compatible provider pointing to a gateway without /v1/models (e.g. opengateway.gitlawb.com/v1)
  2. Use a model like mimo-v2.5-pro
  3. context_limit_for_model() returns None, resolved as 200k

Suggested improvements:

  • Allow users to set per-model context limits via config (e.g. context_limits map in provider config)
  • Support a context_window field in NamedProviderConfig model entries
  • Fall back to probing (send a request and detect context-limit errors) rather than assuming 200k

Activity

  1. added
    enhancement
    on May 31, 2026
  2. added
    priority: medium
    triage: fixed
    on May 31, 2026
  3. 1jehuang commented on May 31, 2026

    @1jehuang
    Owner

    This is now supported via per-model config overrides. In a named provider profile (~/.jcode/config.toml) you can set a per-model context_window (aliases: context_limit, context-window, context-length):

    [providers.my-gateway]
    type = "openai-compatible"
    api_base = "https://opengateway.example.com/v1"
    
    [[providers.my-gateway.models]]
    id = "mimo-v2.5-pro"
    context_window = 131072

    Code path:

    • NamedProviderModelConfig.context_window is defined in crates/jcode-config-types/src/lib.rs (with the aliases above).
    • It's collected into static_context_limits when the provider is built (crates/jcode-base/src/provider/openrouter.rs, ~L1121).
    • OpenRouterProvider::context_window() (crates/jcode-base/src/provider/openrouter_provider_impl.rs, ~L1028) consults self.static_context_limits for the active model before falling back to the live /models catalog or DEFAULT_CONTEXT_LIMIT (200k).

    So a gateway without /v1/models can now have correct per-model windows without probing. The probing-fallback idea from the issue is a separate, optional enhancement.

    If a configured context_window isn't being honored for your gateway model on a current build, please reopen with your (redacted) profile and jcode --version.

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

    enhancementpriority: mediumtriage: fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions