Skip to content

[BUG] AzureOpenAIClient incorrectly handles max_completion_tokens #53598

@stephentoub

Description

@stephentoub

Library name and version

Azure.AI.OpenAI 2.5.0-beta.1

Describe the bug

Making a request to gpt-5 with chat completion while setting MaxOutputTokenCount results in errors when using AzureOpenAIClient but works successfully using OpenAIClient against the same deployment. As shown in the repro below, the only thing that differs is how the client instance is constructed.

Expected behavior

AzureChatClient: Hi! How can I help you today?

ChatClient: Hi! How can I help you today?

Actual behavior

AzureChatClient: HTTP 400 (invalid_request_error: unsupported_parameter)
Parameter: max_tokens

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

ChatClient: Hi! How can I help you today?

Reproduction Steps

#pragma warning disable OPENAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
using OpenAI;
using Azure.Identity;
using System.ClientModel.Primitives;
using Azure.AI.OpenAI;
using OpenAI.Chat;

string endpoint = ...; // ADD ENDPOINT HERE
string deployment = "gpt-5";

ChatClient cc1 = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential()).GetChatClient(deployment);

ChatClient cc2 = new OpenAIClient(new BearerTokenPolicy(new DefaultAzureCredential(), "https://ai.azure.com/.default"), new OpenAIClientOptions()
{
    Endpoint = new Uri($"{endpoint}/openai/v1"),
}).GetChatClient(deployment);

Test(cc1);
Test(cc2);

void Test(ChatClient cc)
{
    try
    {
        var result1 = cc.CompleteChat([ChatMessage.CreateUserMessage("Hello!")], new ChatCompletionOptions { MaxOutputTokenCount = 1024 });
        Console.WriteLine($"{cc.GetType().Name}: {result1.Value.Content[0].Text}");
    }
    catch (Exception ex)
    {
        Console.WriteLine($"{cc.GetType().Name}: {ex.Message}");
    }
    Console.WriteLine();
}

Environment

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientThis issue is related to a non-management packageOpenAIService AttentionWorkflow: This issue is responsible by Azure service team.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions