fix(llm): configurable OpenAI-compatible request transforms for gpt-5.x/o-series models - #88
Open
dnnspaul wants to merge 2 commits into
Open
fix(llm): configurable OpenAI-compatible request transforms for gpt-5.x/o-series models#88dnnspaul wants to merge 2 commits into
dnnspaul wants to merge 2 commits into
Conversation
…AX_TOKENS_PARAM Newer OpenAI models (gpt-5.x, o-series) reject the legacy max_tokens parameter and require max_completion_tokens. The Vercel AI SDK's OpenAI-compatible provider always emits max_tokens (verified up to the latest 3.x line), so calls to such models fail with HTTP 400 and burn through all retries. Add OPENAI_MAX_TOKENS_PARAM (default max_tokens, unchanged behaviour). When set to max_completion_tokens, the parameter is renamed at the transport boundary via the provider's transformRequestBody hook. Validated at startup so typos error out instead of silently falling back.
gpt-5.x/o-series reasoning models reject non-default sampling parameters outright (only the default temperature of 1 is accepted), so the hardcoded temperature: 0.2 in complete() fails with HTTP 400 on every attempt — the same class of failure as the max_tokens rejection. OPENAI_DROP_PARAMS takes a comma-separated list of request parameters to omit from OpenAI-compatible chat calls (typical: OPENAI_DROP_PARAMS=temperature). Applied in the same transformRequestBody hook as the max_tokens rename; unset keeps current behaviour.
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.
Problem
Calls to newer OpenAI models (gpt-5.x, o-series — e.g.
openai/gpt-5.6-luna) through the OpenAI-compatible provider fail on every attempt, in two stages:Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.Unsupported value: 'temperature' does not support 0.2 with this model. Only the default (1) value is supported.—complete()hardcodestemperature: 0.2.The Vercel AI SDK's
@ai-sdk/openai-compatibleprovider serializesmaxOutputTokensunconditionally asmax_tokens(verified up to the latest 3.0.28 — an SDK upgrade does not fix this) and passestemperaturethrough untouched. Each consolidation call therefore 400s and burns through all 3 retries before giving up.Fix
Two independent env knobs, both applied at the transport boundary via the provider's typed
transformRequestBodyhook, both defaulting to current behaviour:OPENAI_MAX_TOKENS_PARAM=max_completion_tokens— renames the token-limit parameter (defaultmax_tokens, unchanged). Validated invalidateConfig(): an unknown value produces a startup error instead of silently falling back.OPENAI_DROP_PARAMS=temperature— comma-separated list of request parameters to omit (e.g.temperature, which reasoning models only accept at the default 1).For gpt-5.x/o-series models, set both. Anthropic/Google paths are untouched (the SDK maps parameters correctly there).
Testing
fetchcapturing the real wire body:max_tokens: 8192,temperature: 0.2(legacy behaviour intact)max_completion_tokens: 8192, nomax_tokens, notemperaturerenameMaxTokensParam,omitRequestParams, and the config validationtsc --noEmitclean; biome clean on all added linesconfig-file.test.ts(fails identically on cleanmain)