"Setting 'max_tokens' and 'max_completion_tokens' at the same time is not supported." #922

Closed
opened 2026-02-20 17:42:23 -05:00 by yindo · 1 comment
Owner

Originally created by @fengpeng-yue on GitHub (Aug 19, 2025).

Issue with current documentation:

Hello, everyone:

I want to set the max_tokens parameter in ChatOpenAI, but I get the following error:
" openai.BadRequestError: Error code: 400 - {'error': {'message': "Setting 'max_tokens' and 'max_completion_tokens' at the same time is not supported.", 'type': 'invalid_request_error', 'code': 'invalid_parameter_combination', 'param': 'max_tokens'}}"

My code is as follows:
from langchain_openai import ChatOpenAI; Agent = ChatOpenAI(model="gpt-4.1",max_tokens=1024); Agent.invoke(messages)

I also tried calling agent.invoke(messages, max_tokens=1024) and Agent = ChatOpenAI(model="gpt-4.1",max_completion_tokens=1024) but it didn't work.

How can I solve this problem?

Idea or request for content:

No response

Originally created by @fengpeng-yue on GitHub (Aug 19, 2025). ### Issue with current documentation: Hello, everyone: I want to set the max_tokens parameter in ChatOpenAI, but I get the following error: " openai.BadRequestError: Error code: 400 - {'error': {'message': "Setting 'max_tokens' and 'max_completion_tokens' at the same time is not supported.", 'type': 'invalid_request_error', 'code': 'invalid_parameter_combination', 'param': 'max_tokens'}}" My code is as follows: `from langchain_openai import ChatOpenAI; Agent = ChatOpenAI(model="gpt-4.1",max_tokens=1024); Agent.invoke(messages)` I also tried calling agent.invoke(messages, max_tokens=1024) and Agent = ChatOpenAI(model="gpt-4.1",max_completion_tokens=1024) but it didn't work. How can I solve this problem? ### Idea or request for content: _No response_
yindo added the documentation label 2026-02-20 17:42:23 -05:00
yindo closed this issue 2026-02-20 17:42:23 -05:00
Author
Owner

@kzh2ang commented on GitHub (Aug 19, 2025):

how do you fixed it ?

@kzh2ang commented on GitHub (Aug 19, 2025): how do you fixed it ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#922