Skip to content

[BUG] ChatCompletionOptions and gpt-5 models #737

@degrover-cn

Description

@degrover-cn

Describe the bug

Using the latest and passing an instance of ChatCompletionOptions with MaxOutputTokenCount set I get this error with most gpt-5 models except chat.

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

If I omit MaxOutputTokenCount simple options work

new ChatCompletionOptions { Temperature = 1, TopP = 1 },

but adding a data source that works with gpt-5-chat fails with gpt-5 or gpt-5-mini, throwing an HTTP 400 error at ChatCompletion chat = await _chatClient.CompleteChatAsync(...

        var options = new ChatCompletionOptions()
        {
            Temperature = (float)0.9,
            TopP = (float)0.95
        };

#pragma warning disable AOAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
options.AddDataSource(new AzureSearchChatDataSource()
{
AllowPartialResults = true,
Strictness = 3,
TopNDocuments = 5,
InScope = !AllowGeneralKnowledge,
Endpoint = new Uri(AISearchUrl),
IndexName = AISearchIndex,
Authentication = DataSourceAuthentication.FromApiKey(AISearchApiKey), // Add your Azure AI Search admin key here
});
#pragma warning restore AOAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

Steps to reproduce

Use the ChatCompletionOptions object. Set MaxOutputTokenCount or add Tools and a DataSource.

Code snippets

OS

Windows

.NET version

.Net 9.0

Library version

2.5.0

Metadata

Metadata

Assignees

Labels

area: serviceThis issue is an inquiry about a bug in the OpenAI service or requesting a new service feature.questionCategory: The issue is seeking information about the library or its usage.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions