Skip to content

max_tokens parameter is no longer supported for gpt-5/chat completion #7863

Closed

Description

@MonkeyLeeT

Description

If we call gpt-5 using a chat completion API (OpenAIChatLanguageModel), we'll hit AI_APICallError: Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.

This is because

max_tokens: maxOutputTokens,
is still setting the deprecated max_tokens instead of max_completion_tokens.

Note that this can be solved by https://github.com/vercel/ai/pull/7848/files since we do override this param for reasoning models.

AI SDK Version

No response

Activity

  1. bardia-pourvakil commented on Aug 8, 2025

    @bardia-pourvakil

    +1

  2. thdxr commented on Aug 8, 2025

    @thdxr
    Contributor

    yeah we're hitting this too

  3. vjayarag commented on Aug 8, 2025

    @vjayarag

    +1

  4. added
    bugSomething isn't working as documented
    provider/openaiIssues related to the @ai-sdk/openai provider
    and removed on Aug 8, 2025
  5. lgrammel commented on Aug 8, 2025

    @lgrammel
    Collaborator

    should be resolved for ai sdk 4 in openai provider 1.3.34

  6. added
    ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` label
    on Oct 15, 2025
  7. vickyRathee commented on Jan 16, 2026

    @vickyRathee

    @lgrammel this is still throwing error with latest version : ` "@ai-sdk/openai-compatible": "^2.0.13" when used with AI gateway providers.

    Do I need to remove the maxOutputTokens? i thought the package automatically handles it and changes to max_completion_tokens for Open AI?

    export function getAIGateway(
      apiKey: string,
      gatewayId: string,
    ) {
      const openAICompatible = createOpenAICompatible({
        name: `cf-openai`,
        baseURL: `${baseURL}/compat`
        apiKey: apiKey,
      });
      return openAICompatible(`openai/${model}`) as unknown as LanguageModel;
    }
    
    const model = getAIGateway(apiKey, gatewayId);
    
    const result = streamText({
          model: model,
          messages: messagesArray,
          maxOutputTokens: MAX_TOKEN,
          temperature: TEMP,
        }); 
    
  8. lgrammel commented on Jul 22, 2026

    @lgrammel
    Collaborator

    Identify issue type

    Identified as Bug
    Confidence: High

    Rationale

    The issue reports a concrete provider incompatibility that causes GPT-5 requests using the existing maxOutputTokens API to fail unexpectedly.

    Evidence

    • Calling GPT-5 through OpenAIChatLanguageModel sends deprecated max_tokens, causing an AI_APICallError that requires max_completion_tokens.
    • The reporter identifies the provider code that sets the incompatible parameter.
    • Multiple users reproduced the failure; a maintainer stated it was addressed in OpenAI provider 1.3.34, while a later user reported similar behavior with @ai-sdk/openai-compatible and an AI gateway.
  9. added theissue type on Jul 22, 2026
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

    ai/providerrelated to a provider package. Must be assigned together with at least one `provider/*` labelbugSomething isn't working as documentedprovider/openaiIssues related to the @ai-sdk/openai providertask-identify-issue-type-done

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions