openai.error.InvalidRequestError: Resource not found -> Model list

I can succesfully list models with curl. Postman also works but I need to enable header “Host”. However I cannot get model list to work in python env:

(base) sergio@Ubuntu-22-04-Python:~/Testingdalle$ python --version
Python 3.10.11
(base) sergio@Ubuntu-22-04-Python:~/Testingdalle$ openai --version
openai 0.27.8

my py script
import openai
openai.api_key = “mykeyhere”
openai.organization = “myorghere”
openai.Model.list()

error thrown
(base) sergio@Ubuntu-22-04-Python:~/ Testingdalle$ ./create_painting.py
Traceback (most recent call last):
File “/home/sergio/Testingdalle/./create_painting.py”, line 16, in
openai.Model.list()
File “/home/sergio/.local/lib/python3.10/site-packages/openai/api_resources/abstract/listable_api_resource.py”, line 60, in list
response, _, api_key = requestor.request(
File “/home/sergio/.local/lib/python3.10/site-packages/openai/api_requestor.py”, line 298, in request
resp, got_stream = self._interpret_response(result, stream)
File “/home/sergio/.local/lib/python3.10/site-packages/openai/api_requestor.py”, line 700, in _interpret_response
self._interpret_response_line(
File “/home/sergio/.local/lib/python3.10/site-packages/openai/api_requestor.py”, line 763, in _interpret_response_line
raise self.handle_error_response(
openai.error.InvalidRequestError: Resource not found

I also tried to encode openai variables but didn’t work either e.g. openai.api_key.encode(‘utf-8’)

I can create API keys, curl and postman work, I assume my api account is valid?!

Please help

Python 3.10.11 - issue one

While the openai python module states “Python 3.7.1+”, another solution to some errors is “Python < 3.10”

Your pasted code has the wrong type of quote character for the key and organization strings.

Want to find out if you have gpt-4? Try this:


import openai
openai.api_key = "sk-xxx"
openai.organization = "org"

def get_gpt_models():
    try:
        gpt_model_ids = [model.id for model in openai.Model.list()["data"] if model.id.startswith("gpt")] 
        return gpt_model_ids
    except Exception as err:
        print(f"Error updating model list: {err}")

print(get_gpt_models())
3 Likes

Thank you @_j , I created and run on python 3.9 env but didn’t work; pasting your code returned the same error “Resource not found”. The quote character in my initial code broke when pasting to this post but it’s correct in the script. Any other ideas please?

You’re a member of the given organization name (not the organization id)?

If you have your own account, own payment method supplied or are in free trial, I would go to platform.openai.com and under API keys, select your own organization as default at the bottom, and generate a new API key. Use that key, but no organization line in the code.

If working then, work backwards to discover the breaking modification if you are attempting to use someone else’s organization.

The error only seems widely evoked for Microsoft Azure users, who can pick a different version of the API. You don’t show being an Azure user as being the case in your code.

Thanks @_j I do have an account with Azure and maybe linked to the user email I use for OpenAI, not sure. I tried as you suggested but still can’t get it to work, same error :frowning:

Assuming your key and org id’s are valid can you please run the following in your dev environment

pip install --upgrade openai

I am also experiencing the same error. I have Python 3.8 and my keys work using the CURL method. I have revoked keys and created ones, and used all the organizations I am part of and also still getting errors. Since I am paying for GPT-4, this is quite frustrating.

Hi and welcome to the Developer Forum!

ChatGPT-4 is not the same system as API GPT-4, they have separate billing systems, you will need to add a payment card to your API account details.

I understand that. I have paid for API as well.

Ok, and what is the exact error you are getting?

Thanks! The exact error I am getting is this one: “InvalidRequestError: Resource not found”
I get it after running the following code:

image

if you go to the playground here OpenAI Platform

and click on the “model” drop down, what does that show?

image

Ok, so you have access to the GPT-4 model, what version of the openai library do you have installed?

image

Thanks for the help!

I would also check that your API key is properly stored in the environment variable, if you are using the export command, make sure you are not using " quotes around the API key,

You should end up with something like this, assume the API key is stored correctly, as a test you can just manually enter it into python as openai.api_key = “your_key”

image

I have checked that and all looks good. In fact, I put directly the string into openai.api_key and I am still getting the exact same error.

Hmmm, where is this environment running? is it a local machine or a VM somewhere?

If it’s not local can you spin up a python env locally to test?

Just for completnes, my python version is 3.10.12

OK. Here is the test I did: I created a new key to start fresh and tested it in two computers: 1) My laptop with the exact same Python version (3.8.10), same OpenAI API (0.28.0), both running WSL in Windows 11.

  1. Test on my laptop works.
  2. Test on a PC w/ the same key and it does not work, and I get the same error.
  3. Created an additional Virtual Environment on the PC, and used the same key, and now it works.

It seems like the Python virtual environment may be corrupt?

Might not be python itself, could be some sub system that handles TCP or networking that’s out of date.