Skip to content

feat(gateway): adapt output token limits to upstream model capabilities #3021

Backlog

Description

@frf12

Feature description

Add a shared, provider-aware way to handle model output token limits, including narrowly bounded recovery from explicit upstream limit rejections.

This is a separate follow-up from #3020 and the DSH integration RFC #3003. It is not a prerequisite for either PR, and the complete mechanism should not be implemented inside the DSH plugin PR.

Problem and proposed solution

A host's generic output default can exceed the limit of the actual model or deployment. During the #3020 review, registering gpt-4.1-mini with only its ID caused DSH 0.2.2-rc.5 to send max_output_tokens: 128000, while the model's documented output limit is 32768. This was observed using the real DSH adapter with an intercepted HTTP request, not a live provider call. A custom deployment or relay can also impose a lower limit than a public model catalog reports.

Please consider a shared design covering:

  • Capability sources and user overrides. Reuse upstream model metadata or an existing catalog where available, and support explicit per-model/provider configuration. Distinguish the model's output capability from the requested generation budget and the context window. Unknown metadata should remain unknown; it need not force every user to fill in every model.
  • Protocol-specific request handling. Define when an omitted output limit should stay omitted, when a protocol requires a default, and how explicit client values and user overrides interact with a known limit. Avoid a single universal default or blanket clamping based on potentially stale catalog data.
  • Deterministic rejection recovery. If an upstream explicitly rejects an output limit and states an unambiguous supported maximum, evaluate reducing the limit and retrying within a small bound. If learned limits are cached, scope them to the actual provider/deployment and model, with a defined lifetime. This must not become a retry after a timeout, partial response, or other indeterminate delivery.

Core should continue to own admission and capacity decisions. Any adjusted outbound request must follow the existing gate and retry contracts; this feature must not bypass a check already bound to different request bytes.

Alternatives considered

For #3020, retaining/applying known or explicitly configured model limits and documenting the configuration path is sufficient. A new complete model catalog, provider discovery, automatic clamping, and adaptive retry are outside that PR's scope.

Magpie is a useful reference rather than a requirement to copy its policy:

  • It combines user overrides, upstream model metadata, and models.dev, and writes suitable limits into host configuration.
  • It can learn a smaller output limit from an explicit upstream rejection and retry, with the learned limit retained for that process.
  • Its handling differs across protocols and routes; it does not blindly replace every explicit client budget with a catalog value.

Additional context

Activity

  1. added
    enhancement
    on Dec 3, 2026
  2. moved this from Todo to In progress in PowerContexton Dec 3, 2026
  3. added
    module:gateway
    on Dec 4, 2026
  4. hireview001 commented on Dec 4, 2026

    @hireview001
    Collaborator

    This issue belongs to the Gateway module. @frf12, please lead follow-up, with support from @happy-v587, @NeverENG. Please provide a substantive response within 72 hours of issue creation, outlining the proposed disposition, any additional information needed, or the next investigation steps. After sufficient discussion and agreement on the scope and acceptance criteria, a contributor who volunteers to take it on can undertake implementation.

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

    enhancementmodule:gateway

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions