#Getting a 403 Forbidden Error: openai.PermissionDeniedError

1 messages · Page 1 of 1 (latest)

spring yarrow
#

Hi there, I've looked everywhere and haven't found anything that has really helped me.

I'm trying to connect to the completions part of the api, and I've been getting the same error: "openai.PermissionDeniedError: Error code: 403.

Below is my code script:

def chat():

from openai import OpenAI
import httpx

key = {my key}

proxies = {

    "http://": "http://proxy1",
    "https://": "http://proxy2"

}

headers = {

    "Content-Type": "application/json",
    "Authorization": "Bearer {key}"
}

httpxClient = httpx.Client(proxies = proxies, headers = headers, timeout = None) # Add a Custom Http Client


client = OpenAI(
    
    api_key = key,
    http_client = httpxClient
)

 chat = client.chat.completions.create( <-------- THE ERROR
    messages=[
        {"role": "user", "content": "Say this is a test"},
        {"role": "system", "content": "Please write a haiku about a fridge"}
    ],
    model="gpt-3.5-turbo"
)

print(chat.choices[0].message['content'])

I have made requests through httpx.post with "https://api.openai.com/v1/chat/completions" in a seperate module, and I get a 200 OK Response - does anybody have any ideas?

#

I've also noticed this from the docs:

Python Library Error Type: PermissionDeniedError
Cause: You don't have access to the requested resource.
Solution: Ensure you are using the correct API key, organization ID, and resource ID.

I do not have an org, my API Key is correct, but what is the Resource ID? The model?