Error: The v1 Assistants API has been deprecated

Hello,

I struggle with the transition from v1 to v2 API-calls in Python scripts. A previous easy task like listing all assistants breaks. Script code:


from openai import OpenAI

aia_api_key = “***”
gpt_model = “gpt-4o-mini”

client = OpenAI(api_key=aia_api_key)

my_assistants = client.beta.assistants.list(
order=“desc”,
limit=“20”,
)
print(my_assistants.data)

After reading about migration, I tried change “client=” to this:

client = OpenAI(api_key=aia_api_key, default_headers={“OpenAI-Beta”: “assistants=v2”})

Error output still the same:


Traceback (most recent call last):
File “D:\imai\aia\test.py”, line 8, in
my_assistants = client.beta.assistants.list(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\py\Lib\site-packages\openai\resources\beta\assistants\assistants.py”, line 313, in list
return self._get_api_list(
^^^^^^^^^^^^^^^^^^^
File “D:\py\Lib\site-packages\openai_base_client.py”, line 1282, in get_api_list
return self._request_api_list(model, page, opts)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\py\Lib\site-packages\openai_base_client.py”, line 1127, in _request_api_list
return self.request(page, options, stream=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “D:\py\Lib\site-packages\openai_base_client.py”, line 922, in request
return self._request(
^^^^^^^^^^^^^^
File “D:\py\Lib\site-packages\openai_base_client.py”, line 1013, in _request
raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: “The v1 Assistants API has been deprecated. Please try again by setting the header ‘OpenAI-Beta: assistants=v2’. See the migration guide for more information: https://platform.openai.com/docs/assistants/migration.”, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: ‘invalid_beta’}}

I can not create threads or do anything with old v1 scripts without receiving this error message. I can interact with gpt assistants v2 very simple like this:


response = client.chat.completions.create(
model = gpt_model,
messages = [
{
“role”: “user”,
“content”: user_input
}
]
)
print(response.choices[0].message.content)

That works fine for single input and output. But what about assistants and threads? Are the old “client.beta.”-calls obsolete? I can not find any good assistants v2 documentation for understanding this.

Is the problem with the line:

client = OpenAI(api_key=aia_api_key, default_headers={“OpenAI-Beta”: “assistants=v2”})

?

How to send a proper assistants=v2 header that includes api key?

You do not need to force a header on OpenAI’s Python library.

Instead, you must update the Python openai package, which was switched to send v2 some time ago.

pip install --upgrade openai

Thank you very much. I did upgrade to 1.20.0 after reading the migration docs, but seems like I misunderstood something there. Now it works, tx!

1 Like

Glad that was a quickie! You will now also be able to use the API methods for vector stores and streaming helpers, etc.