openai / openai-python

The official Python library for the OpenAI API
https://pypi.org/project/openai/
Apache License 2.0
22.22k stars 3.08k forks source link

AzureOpenAI chat completion endpoint does not recognize max_completion_tokens #1724

Closed fladhak closed 1 week ago

fladhak commented 1 week ago

Confirm this is an issue with the Python library and not an underlying OpenAI API

Describe the bug

With the o-1 release, max_tokens was deprecated in favor of max_completion_tokens, and while that argument works with the OpenAI client, it doesn't seem to be working with the AzureOpenAI client. I see the following error:

BadRequestError: Error code: 400 - {'error': {'message': 'Unrecognized request argument supplied: max_completion_tokens', 'type': 'invalid_request_error', 'param': None, 'code': None}}

To Reproduce

import os
from openai import AzureOpenAI

client = AzureOpenAI(
  azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"), 
  api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
  api_version="2024-08-01-preview"
)

m = {'role': 'user', 'content': "Hello!"}
client.chat.completions.create(messages=[m], model='gpt-4o', max_completion_tokens=100)

Code snippets

No response

OS

linux

Python version

3.11.9

Library version

1.46.0

RobertCraigie commented 1 week ago

Thanks for reporting! I'm going to close this as it's related to the Azure API and not the SDK itself.

cc @kristapratico to share any details from the azure side.

kristapratico commented 1 week ago

@fladhak the Azure API does not support max_completion_tokens with chat completions yet. I expect it to be supported very soon. You can follow the what's new page for updates.