My python package does'nt work anymore with V2 Assistant

I wrote a python package with V1 lib version.
I created an Assistant with associated function calls and documents via online platform UI.
I wrote same apps (telegram bots) using the Assistant via API .
Everithing was working till few days ago

Now, the Assistant has been updated to v2, and the docs has been trasformed into vectors.

My apps does’nt work anymore with my Assistant as they require V2 API libs.
I cannot upgrade to V2 versione as the latest available version is 1.29.x
Even more I could’nt find how to change my code as some methods (retrieve e.g.) seems not anymore available.

here the methods call list I need to convert/check:


any suggestions/code sample/reference ?

Thank you in advance for any support!

If you are using the Python library, just use pip to install a fixed past version (that doesn’t send the v2 header by default), would maintain the function you had.
pip install openai<1.20 or such.

There is nothing much to change except the vector store method for file_search that replaces retrieval, and some changes in how certain parameters are passed.

Simply go to “API Reference” and compare the v1 assistants at the bottom of the list of indexes in help to the main assistants.

1 Like

I installed the 1.19 in pycharm in Setting UI and still I get the following error:

The requested model ‘gpt-4o-2024-05-13’ cannot be used with the Assistants API in v1. Follow the migration guide to upgrade to v2:

p.s. may be I’m a little dumb but in The API Reference I find the V1 reference but I cannot find the V2 refererence :woozy_face:
All REST calls in the upper references (main assistants) are referring to v1 version afaik

1 Like

So you upgrade the model and and the library and then code doesn’t work. OK.

Here is “migration guide” which really is just the attachment of code interpreter or file_search in difference

I cannot understand how to do.

here is my client creation:

self.client = OpenAI(api_key=os.getenv(“API_KEY”),default_headers={“OpenAI-Beta”: “assistants=v2”})

here is where error occours (self.client.beta.threads.runs.create):

async def submit_message(self,assistant_id, thread_id, user_message):
    # when a thread is already available create message and run the query
    # - create a message
    # - run the thread
    #@ chck run sul thread
    message = self.client.beta.threads.messages.create(thread_id=thread_id, role="user", content=user_message)
    return, self.client.beta.threads.runs.create(
        instructions=instructions + 'Oggi è '"%A %d/%m/%Y")

and here the error:

openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: “The requested model ‘gpt-4o-2024-05-13’ cannot be used with the Assistants API in v1. Follow the migration guide to upgrade to v2:”, ‘type’: ‘invalid_request_error’, ‘param’: ‘model’, ‘code’: ‘unsupported_model’}}

The assistant was create with UI and it works correctly in the openai platform.
My python liv version is 1.30.1

If you really have installed and are running the latest version of the openai library module, you do not need to set any header. You also do not need to set a key on the client if you have an environment variable.

You may have multiple installs, such as not installing openai with administrator rights on your system-wide Python install.

Remove the client parameters from your code. Then diagnose your version faults by running this the same way as your script:

import openai


“Installed in pycharm” is just problematic. You may need to pip uninstall openai in multiple contexts, and then if your python is a system install (program files in windows), only install from administrator command prompt or sudo.

1 Like

Wov. It was only a question of lib. I was sure it was 1.30.1 It was 1.19.
That was it!

The version check advise clicked something in my old brain :slight_smile:
Now it is running with no other change

1 Like