Subject: Error: 'OpenAI' Object Has No Attribute 'batches'

When Creating Batch Jobs I’m encountering an error while attempting to create batch jobs using the OpenAI API. The code snippet below produces an AttributeError:

batch_input_file_id = batch_input_file.id

client.batches.create(
input_file_id=batch_input_file_id,
endpoint=“/v1/chat/completions”,
completion_window=“24h”,
metadata={
“description”: “nightly eval job”
}
)

The error message states: AttributeError: 'OpenAI' object has no attribute 'batches' .

What is the recommended approach for creating batch jobs in the current version of the OpenAI API?

The openai SDK module validates input. Not allowing you to send what it doesn’t know.

So you need to install a quite new version of software to try a feature released two weeks ago.

Or instead make your requests yourself with a https package so that using AI models isn’t a co-mingled locked-in mess.

2 Likes

Try %pip install --upgrade openai --quiet to install the new SDK

I tried this but still have the same issue. For some reason I only face it with client.batches.list(limit=10) and not with client.batches.create…

I’ve faced the same error. I just realised, that I forgot to update the openai lib inside the virtual env, where my jupyter notebook works. I hope it’ll help someone. To check current lib’s version use openai.__version__