Open AI error: "InvalidRequestError: Resource not found". Please help to fix.

AIoTMR Architect 40 Reputation points
2023-03-07T06:45:55.61+00:00

Dear Team

Could you please help us fixing this error? Code has been taken from sample given and key has been tried as key1 and key2 both separately. Same error is found.

python result: openai.error.InvalidRequestError: Resource not found

#Note: The openai-python library support for Azure OpenAI is in preview.
import os
import openai
openai.api_type = "azure"
openai.api_base = "https://explore123.openai.azure.com/"
openai.api_version = "2022-12-01"
#openai.api_key = os.getenv("66bcffe0ed6c440dba76940d04a7bb03")
openai.api_key = "<key>"

response = openai.Completion.create(
  engine="text-davinci-002",
  prompt="Classify the following news article into 1 of the following categories: categories: [Business, Tech, Politics, Sport, Entertainment]\n\nnews article: Donna Steffensen Is Cooking Up a New Kind of Perfection. The Internet’s most beloved cooking guru has a buzzy new book and a fresh new perspective:\n\nClassified category: Business",
  temperature=0,
  max_tokens=60,
  top_p=1,
  frequency_penalty=0,
  presence_penalty=0,
  best_of=1,
  stop=None)

print(response)

Result:

Traceback (most recent call last):
  File "test1.py", line 19, in <module>
    stop=None)
  File "/home/user/.local/lib/python3.6/site-packages/openai/api_resources/completion.py", line 31, in create
    return super().create(*args, **kwargs)
  File "/home/user/.local/lib/python3.6/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 67, in create
    "post", url, params, headers, stream=stream
  File "/home/user/.local/lib/python3.6/site-packages/openai/api_requestor.py", line 129, in request
    resp = self.interpret_response(rbody, rcode, rheaders, stream=stream)
  File "/home/user/.local/lib/python3.6/site-packages/openai/api_requestor.py", line 348, in interpret_response
    return self.interpret_response_line(rbody, rcode, rheaders, stream)
  File "/home/user/.local/lib/python3.6/site-packages/openai/api_requestor.py", line 368, in interpret_response_line
    rbody, rcode, resp.data, rheaders, stream_error=stream_error
openai.error.InvalidRequestError: Resource not found

======================================================================

Curl Result:  -> no error shown but how can i see the result?

curl https://explore123.openai.azure.com/openai/deployments/text-davinci-002/completions?api-version=2022-12-01   -H "Content-Type: application/json"   -H "api-key: 66bcffe0ed6c440dba76940d04a7bb03"   -d '{
  "prompt": "Classify the following news article into 1 of the following categories: categories: [Business, Tech, Politics, Sport, Entertainment]\n\nnews article: Donna Steffensen Is Cooking Up a New Kind of Perfection. The Internet’s most beloved cooking guru has a buzzy new book and a fresh new perspective:\n\nClassified category: Business",
  "max_tokens": 60,
  "temperature": 0,
  "frequency_penalty": 0,
  "presence_penalty": 0,
  "top_p": 1,
  "best_of": 1,
  "stop": null
}'
{"id":"cmpl-6rLFaLc8zTYo8oHbjA5WNm5Tp6i7k","object":"text_completion","created":1678171090,"model":"text-davinci-002","choices":[{"text":"","index":0,"finish_reason":"stop","logprobs":null}],"usage":{"prompt_tokens":73,"total_tokens":73}}



Regards
Champak
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
2,646 questions
{count} votes

9 answers

Sort by: Most helpful
  1. Ahi, Sercan (KIT) 35 Reputation points
    2023-05-08T03:48:49.5733333+00:00

    I had the same issue and resolved it by updating api-version query parameter. Specifically,

    # Before
    openai.api_version = "2022-12-01"
    
    # After
    openai.api_version = "2023-03-15-preview"
    

    FYI, I am using Python 3.10.9 and openai==0.27.6.

    7 people found this answer helpful.

  2. Minjie 20 Reputation points Microsoft Employee
    2023-03-21T23:01:03.4733333+00:00

    After upgrading python version to 3.8 and later, my issue was resolved.

    4 people found this answer helpful.

  3. Shaun Scovil 10 Reputation points
    2023-05-11T03:31:56.21+00:00

    I ran into this issue tonight and found two problems that others might be having as well:

    1. When I copied the endpoint from Azure, it had a trailing slash that wasn't being stripped by the openai library, resulting in a URL like: https://xxxxxxxx.openai.azure.com//openai/deployments/... (note the double slashes).
    2. At first I was using API version 2022-12-01, but when I switched to 2023-03-15-preview it worked.

    Hope this helps save a few headaches. :-)

    2 people found this answer helpful.
    0 comments No comments

  4. Anonymous
    2023-03-16T01:29:26.47+00:00

    I was also stuck with a 404 Resource Not Found response when attempting to access my deployment of chat completions (with correct API base and Key set). Networking remains on the default 'All Networks', I'm using Postman running on development laptop.

    I've discovered white space characters at the end of API base & key, and at the end of the api-version parameter - a result of copying from the Azure portal and / or the ChatGPT playground. This wasn't obvious until viewing the cURL code snippet in Postman. Deleting these solved the problem.

    1 person found this answer helpful.

  5. Gianluca D'Ardia 5 Reputation points Microsoft Employee
    2023-04-11T12:16:42.8433333+00:00

    I have the same errror, once moved code into Azure App Service. From local everything works fine, but once deployed into app service same error "python result: openai.error.InvalidRequestError: Resource not found" arise.
    Any suggestion? Permission issue? I simply used endpoint provide by portal and key Does anyone already faced same issue? Thanks

    1 person found this answer helpful.
    0 comments No comments