Batch API calls in Azure OpenAI yield OperationNotSupported errors

Pradeep Dasigi 20 Reputation points
2024-10-21T21:09:43.5533333+00:00

I created "Global Batch" deployments in the US East region for GPT4 Turbo, GPT 4o, and GPT 4o-mini models. Following the code samples in this page, I tried to upload a file for a batch job using the following Python code:

from openai import AzureOpenAI

AZURE_ENDPOINT = "endpoint"
API_KEY = "api_key"

client = AzureOpenAI(
        azure_endpoint = AZURE_ENDPOINT,
        api_key= API_KEY,
        api_version="2024-10-01-preview"
)
# Upload a file with a purpose of "batch"
file = client.files.create(
        file=open("test.jsonl", "rb"),
        purpose="batch"
)

The following is the data file (test.jsonl):

{"custom_id": "task-0", "method": "POST", "url": "/chat/completions", "body": {"model": "gpt-4o-batch", "messages": [{"role": "system", "content": "You are an AI assistant that helps people find information."}, {"role": "user", "content": "When was Microsoft founded?"}]}}

Note that the model name ("model") refers to the name of my deployment. When I run the code above, I get the following error:

openai.BadRequestError: Error code: 400 - {'error': {'code': 'OperationNotSupported', 'message': 'The chatCompletion operation does not work with the specified model, gpt-4o. Please choose different model and try again. You can learn more about which models can be used with each operation here: https://go.microsoft.com/fwlink/?linkid=2197993.'}}

I confirmed that chat completions do work for the model using the standard API. Moreover, I am being able to create a batch job on the AI Studio with the same model and the same data file above, and the job ran successfully. I am not being able to figure out why the Python batch API call does not work. Please help!

Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,080 questions
{count} votes

Accepted answer
  1. Pavankumar Purilla 8,335 Reputation points Microsoft External Staff Moderator
    2024-10-23T10:53:35.53+00:00

    Hi Pradeep Dasigi,

    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer.

    Issue:
    Batch API calls in Azure OpenAI yield OperationNotSupported errors**

    Solution:**
    For anyone else facing the same issue, the endpoint needs to be just https://[deployment-name].openai.azure.com.

    The deployment's info in the AI Studio shows a much longer "Target URI" under "Endpoint", which looks like https://[deployment-name].openai.azure.com/openai/deployments/[deployment-name]/chat/completions?api-version=... . I was using this entire string earlier, which resulted in the misleading error message above.

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    Hope this helps. Do let us know if you have any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful.

    3 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Pradeep Dasigi 20 Reputation points
    2024-10-22T23:36:08.0333333+00:00

    Solved. For anyone else facing the same issue, the endpoint needs to be just https://[deployment-name].openai.azure.com.

    The deployment's info in the AI Studio shows a much longer "Target URI" under "Endpoint", which looks like https://[deployment-name].openai.azure.com/openai/deployments/[deployment-name]/chat/completions?api-version=... . I was using this entire string earlier, which resulted in the misleading error message above.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.