我在使用在 OpenAI.com 创建的 API 密钥发出请求时遇到身份验证错误
这是我使用的代码:
from openai import OpenAI
client = OpenAI(api_key = "Lkey")
response = client.completions.create(
model = "gpt-3.5-turbo-instruct",
prompt = "What is OpenAI?"
)
print(response)
即使我在 OpenAI.com 创建了一个 API 密钥,我也收到一条错误,指出该密钥不存在,而不是拥有完成对象:
AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: Lkey. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}
我在 VS Code 上尝试了所有扩展和在线编辑器,但没有任何效果。
试试这个:
from openai import OpenAI
Lkey = "your_api_key_goes_here"
client = OpenAI(api_key = Lkey)
response = client.completions.create(
model = "gpt-3.5-turbo-instruct",
prompt = "What is OpenAI?"
)
print(response)