openai.BadRequestError: Error code: 400 - {'error': {'message': 'Unrecognized request argument supplied: max_completion_tokens', 'type': 'invalid_request_error', 'param': None, 'code': None}}
I'm encountering an issue with Azure OpenAI when attempting to use the max_completion_tokens
parameter in a request. The error I receive is as follows:
openai.BadRequestError: Error code: 400 - {'error': {'message': 'Unrecognized request argument supplied: max_completion_tokens', 'type': 'invalid_request_error', 'param': None, 'code': None}}
Context
I understand that OpenAI has deprecated the max_tokens
parameter in favor of max_completion_tokens
for the new "o1" model series. This change accommodates reasoning tokens, which are not returned to users but impact the overall token limit and cost.
The Azure OpenAI documentation (source) indicates that:
max_completion_tokens
was added to supporto1-preview
ando1-mini
models, andmax_tokens
does not work with the o1 series models.
However, I noticed that for GPT-4 (e.g., version turbo-2024-04-09
), the max_tokens
parameter is still required instead, and using max_completion_tokens
triggers the error mentioned earlier. For GPT-4o-mini and GPT-4o, max_completion_tokens
works as expected, but this inconsistency seems unusual.
Question
Could this behavior for GPT-4 models be intentional, or might it be an oversight? If it is intentional, is there a roadmap or plan to unify parameter usage across models, or any updates expected to ensure consistency? Alternatively, is it possible that I may be missing something in the implementation or documentation?
Reproduction
Here’s the code causing the issue:
import os
from openai import AzureOpenAI
endpoint = os.getenv("ENDPOINT_URL")
deployment = os.getenv("DEPLOYMENT_NAME")
api_key = os.getenv("AZURE_API_KEY")
if endpoint is None:
raise ValueError("ENDPOINT_URL is not set")
if api_key is None:
raise ValueError("AZURE_API_KEY is not set")
client = AzureOpenAI(
azure_endpoint=endpoint,
api_version="2024-09-01-preview",
api_key=api_key,
)
messages = [
{
"role": "system",
"content": [
{
"type": "text",
"text": "You are an AI assistant that helps people find information.",
}
],
}
]
completion = client.chat.completions.create(
model=deployment,
messages=messages,
max_completion_tokens=800, # Issue is here
temperature=0.7,
top_p=0.95,
frequency_penalty=0,
presence_penalty=0,
stop=None,
stream=False,
)
print(completion.to_json())
Traceback
Traceback (most recent call last):
File "/path/to/sample_code.py", line 35, in <module>
completion = client.chat.completions.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
openai.BadRequestError: Error code: 400 - {'error': {'message': 'Unrecognized request argument supplied: max_completion_tokens', 'type': 'invalid_request_error', 'param': None, 'code': None}}
Environment
- Python Version: 3.12.3
- OpenAI Library Version: 1.58.1
Could you clarify or provide guidance on this issue?