Repository navigation
fix(studio): retry custom gateways with max_completion_tokens after max_tokens 400 (#10787) - #10837
Merged
danielhanchen merged 4 commits intoOct 1, 2026
Conversation
Souravrajvi0
force-pushed
the
feat/custom-max-completion-tokens-3644
branch
from
September 12, 2026 17:24
79b9af8 to
a4a0af2
Compare
This was referenced Sep 14, 2026
Souravrajvi0
force-pushed
the
feat/custom-max-completion-tokens-3644
branch
from
September 17, 2026 03:58
bc163da to
47b0b20
Compare
This comment has been minimized.
This comment has been minimized.
Use max_completion_tokens for OpenAI and Azure Foundry base URLs via _set_chat_completions_max_tokens. For other custom OpenAI-compatible gateways (e.g. KI:connect), keep max_tokens on the first attempt and retry once with max_completion_tokens when the upstream returns 400 unsupported_parameter for max_tokens. Adds focused regression tests; streaming change is a mechanical re-indent for the existing retry loop only.
…i#10787) Per review on unslothai#10837, rely on provider_type openai for max_completion_tokens and error-driven retry for custom gateways (same approach as unslothai#10856), avoiding hostname-based field inference on custom base URLs.
Souravrajvi0
force-pushed
the
feat/custom-max-completion-tokens-3644
branch
from
September 23, 2026 03:24
f163c0e to
240d15b
Compare
This comment has been minimized.
This comment has been minimized.
…f reindenting the stream body
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #10787.
A
customprovider pointing at a gateway that only acceptsmax_completion_tokens(Azure-hosted gpt-5.x / o-series behind OpenAI-compatible proxies, e.g. KI:connect) failed every request withUnsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.Onlyprovider_type == "openai"sentmax_completion_tokens.Fix
max_tokensfor every non-OpenAI provider), so vLLM, llama.cpp and other servers that only knowmax_tokenssee no difference.max_tokens(param == "max_tokens"withcode == "unsupported_parameter"or a message mentioningmax_completion_tokens; substring fallback for non-JSON bodies), the request is resent once withmax_completion_tokens._stream_post_retrying_max_tokenswraps thestream("POST", ...)call. The status check happens before anything is yielded, so the retry is invisible to the client; the stream body itself is untouched. Any other 400, or a failing retry, surfaces exactly as before.chat_completion: same one-shot retry beforeraise_for_status().Tests
studio/backend/tests/test_external_provider_max_tokens_field.pydrives the real client against a loopback HTTP server: stream and non-stream retry on the wire, an unrelated 400 is not retried, and the error-matching cases. The two wire tests fail with the call sites reverted.