Azure OpenAI Batch API resource not found

Mark 20 Reputation points
2024-11-27T08:31:36.0266667+00:00

I followed the instructions in this article

import json
import os

from dotenv import load_dotenv
from openai import AzureOpenAI

load_dotenv()

client = AzureOpenAI(
    api_key=os.getenv("AZURE_OPENAI_KEY"),
    api_version="2024-07-18",
    azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT")
)
from openai import AzureOpenAI

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

with open('tasks.jsonl', 'w') as f:
    for entry in data:
        f.write(json.dumps(entry) + '\n')

file = client.files.create(
    file=open('tasks.jsonl', 'rb'),
    purpose='batch',
)

But when I call the batch api

batch = client.batches.create(
  input_file_id=file.id,
  endpoint="/chat/completions",
  completion_window="24h"
)

I get the following error

NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}

I tried using this jsonl file to run a Batch Job through Azure Ai Studio and it worked fine. Can you please help?

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

Accepted answer
  1. navba-MSFT 26,480 Reputation points Microsoft Employee
    2024-11-27T08:39:00.15+00:00

    @Mark Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    .

    Please update your code to use the api_version="2024-10-01-preview". This should resolve the issue.

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

    .

    Hope this helps. If you have any follow-up questions, please let me know. I would be happy to help.

    **

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.