Skip to content

Unified provider sends max_tokens to OpenAI reasoning models #653

Description

@n1ckoates

ai-gateway-provider’s Unified route currently creates its models via @ai-sdk/openai-compatible:

const unified = createUnified();
const model = aigateway(unified('openai/o1-mini'));

When used with AI SDK’s standardized maxOutputTokens, the outgoing Chat Completions request contains:

{
  "model": "openai/o1-mini",
  "max_tokens": 1000
}

OpenAI reasoning models reject this field and require max_completion_tokens instead:

Unsupported parameter: 'max_tokens' is not supported with this model.
Use 'max_completion_tokens' instead.

The native Cloudflare OpenAI adapter does not have the issue:

const openai = createOpenAI();
const model = aigateway(openai.chat('o1-mini'));

That route uses @ai-sdk/openai, which performs the correct OpenAI-specific parameter mapping.

Suggested fix: have createUnified() supply transformRequestBody to its createOpenAICompatible instance. When Cloudflare’s model-capability metadata identifies an OpenAI reasoning model, move max_tokens to max_completion_tokens.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions