Skip to content

fix(llm): configurable OpenAI-compatible request transforms for gpt-5.x/o-series models - #88

Open
dnnspaul wants to merge 2 commits into
MAnders333:mainfrom
dnnspaul:fix/openai-max-completion-tokens
Open

fix(llm): configurable OpenAI-compatible request transforms for gpt-5.x/o-series models#88
dnnspaul wants to merge 2 commits into
MAnders333:mainfrom
dnnspaul:fix/openai-max-completion-tokens

Conversation

@dnnspaul

@dnnspaul dnnspaul commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

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:

  1. Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.
  2. After fixing (1): Unsupported value: 'temperature' does not support 0.2 with this model. Only the default (1) value is supported.complete() hardcodes temperature: 0.2.

The Vercel AI SDK's @ai-sdk/openai-compatible provider serializes maxOutputTokens unconditionally as max_tokens (verified up to the latest 3.0.28 — an SDK upgrade does not fix this) and passes temperature through 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 transformRequestBody hook, both defaulting to current behaviour:

  • OPENAI_MAX_TOKENS_PARAM=max_completion_tokens — renames the token-limit parameter (default max_tokens, unchanged). Validated in validateConfig(): 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

  • End-to-end verification with a stubbed fetch capturing the real wire body:
    • default mode: max_tokens: 8192, temperature: 0.2 (legacy behaviour intact)
    • compat mode: max_completion_tokens: 8192, no max_tokens, no temperature
  • New unit tests for renameMaxTokensParam, omitRequestParams, and the config validation
  • tsc --noEmit clean; biome clean on all added lines
  • Full suite: 646 tests, 1 pre-existing environment-dependent failure in config-file.test.ts (fails identically on clean main)

…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.
@dnnspaul dnnspaul changed the title fix(llm): make OpenAI token-limit parameter configurable via OPENAI_MAX_TOKENS_PARAM fix(llm): configurable OpenAI-compatible request transforms for gpt-5.x/o-series models Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant