Description
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
- DSH implementation: feat(dsh): register the gateway as a model route and switch the plugin per session #3020; related RFC: docs(rfc): propose a PowerContext gateway model route for DSH #3003.
- Provider-specific compatibility also matters: bug(gateway): a Codex subscription refuses every request that carries max_output_tokens #2794 documented a subscription backend rejecting the output-limit field itself.
- Magpie capability precedence.
- Magpie DSH model budget configuration.
- Magpie deterministic limit-rejection handling.
- GPT-4.1 mini output limit.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn progress
Activity
hireview001 commentedon Dec 4, 2026
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.