Azure OpenAI: maxTokens Error and Reasoning Summary Extraction
I’m experiencing issues with Azure OpenAI using LangChain’s AzureChatOpenAI
class and wanted to share my findings.
The Problem
When using AzureChatOpenAI with GPT-5, I’m getting this error:
400 Unsupported parameter: ‘maxTokens’ is not supported with this model. Use
‘max_completion_tokens’ instead.
However, even when I rswitch to maxCompletionTokens, the error persists. Only after I remove maxTokens entirely from the constructor it works
Azure vs OpenAI Configuration Differences
I’ve noticed some key differences between ChatOpenAI and AzureChatOpenAI:
For OpenAI (works):
const model = new ChatOpenAI({
model: "gpt-5",
useResponsesApi: true,
maxTokens: 16384, // Works fine
});
const response = await model.invoke(messages, {
reasoning: { effort: "low", summary: "detailed" }
});
For Azure (error with max_tokens):
const model = new AzureChatOpenAI({
azureOpenAIApiKey: process.env.INTERNAL_AZURE_OPENAI_API_KEY,
azureOpenAIApiInstanceName: "resource-name",
azureOpenAIApiDeploymentName: "gpt-5",
azureOpenAIApiVersion: "2024-10-01-preview",
reasoning: { effort: "low" }, // Must be in constructor for Azure
// Cannot use maxTokens or maxCompletionTokens - causes 400 error
});
Questions
- Is maxTokens supported for Azure OpenAI GPT-5 deployments? The error suggests
it isn’t, but I can’t find this documented anywhere. - Can we extract reasoning summaries from Azure OpenAI? For OpenAI, passing
reasoning to the invoke method works (as mentioned in the original post). For
Azure, the documentation suggests putting reasoning in the constructor, but I
cannot verify if reasoning summaries are actually extractable from
additional_kwargs. - Is this a LangChain bug? Could LangChain be sending max_tokens to Azure OpenAI
even when it’s not specified in the constructor?
Environment
- @langchain/openai: 0.6.14
- Azure OpenAI API Version: 2024-10-01-preview
- Model: gpt-5
Has anyone successfully used Azure OpenAI GPT-5 with LangChain and extracted
reasoning summaries? Any insights would be appreciated!