OpenAI认证的问题

huangapple go评论82阅读模式
英文:

Problems with OpenAI Authentification

问题

I've translated the non-code part of your text as you requested:

"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 one 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 authentication 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"

If you need assistance with the code or have further questions, feel free to ask.

英文:

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?

答案1

得分: 0

您的环境变量就像一个字典,用于检索的代码应该与示例代码匹配:

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

但是,您必须首先设置环境键

从您的代码看,似乎您只想硬编码该值,这种情况下,您的代码应该如下所示:

import openai
openai.organization = "org-CXk0SUzbnyzzCLcaSBCFAV64"
openai.api_key = "sk-**********************************************9Q"
openai.Model.list()
英文:

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()

huangapple
  • 本文由 发表于 2023年6月29日 18:53:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580372.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定