0

I've got some problems with the Authentification to OpenAI in my python code. It seems like, OpenAI doesn't accept my key. I did a new on and tried it with other ones before. I always get the same issues. I just copied and pasted the key, same for the organization. There isn't a typo. There is another problem, but I don't know, why the authentifitaion failed.

Here is my code: I used it in the same way like the OpenAI Website https://platform.openai.com/docs/api-reference/authentication?lang=python

import os
import openai
openai.organization = "org-CXk0SUzbnyzzCLcaSBCFAV64"
openai.api_key = os.getenv("sk-**********************************************9Q")
openai.Model.list()

It produces the follwing error:

openai.error.AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>', or you can set the environment variable OPENAI_API_KEY=<API-KEY>). If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'. You can generate API keys in the OpenAI web interface. See https://onboard.openai.com for details, or email support@openai.com if you have any questions.

Did anyone had the some issues before? Are there any solutions?

Arenosa
  • 3
  • 2

1 Answers1

0

Your environment variables are like a dictionary, and the code to retrieve should match the sample code:

openai.api_key = os.getenv("OPENAI_API_KEY")

However, you have to set the environment keys first.

From your code, it looks like you just want to hard code the value, in which case your code should look like:

import openai
openai.organization = "org-CXk0SUzbnyzzCLcaSBCFAV64"
openai.api_key = "sk-**********************************************9Q"
openai.Model.list()
import random
  • 3,054
  • 1
  • 17
  • 22
  • @Arenosa, please edit your question with changes and include error messages. Read [ask] for more guidance on how to ask a good question. – import random Jun 29 '23 at 11:49