跳转至

认证

OpenAI API 使用 API 密钥进行认证。访问您的 API 密钥页面检索您将在请求中使用的 API 密钥。

记住,你的 API 密钥是一个秘密!不要与他人共享或在任何客户端代码(浏览器,应用程序)中公开它。 生产请求必须通过您自己的后端服务器路由,您的 API 密钥可以从环境变量或密钥管理服务安全地加载。

All API requests should include your API key in an Authorization HTTP header as follows:

Authorization: Bearer YOUR_API_KEY Requesting organization For users who belong to multiple organizations, you can pass a header to specify which organization is used for an API request. Usage from these API requests will count against the specified organization's subscription quota.

Example curl command:

1
2
3
curl https://api.openai.com/v1/models \
 -H 'Authorization: Bearer YOUR_API_KEY' \
 -H 'OpenAI-Organization: org-HW93VY7Oko7ptiKrGabG7oIM'

Example with the openai Python package:

1
2
3
4
5
import os
import openai
openai.organization = "org-HW93VY7Oko7ptiKrGabG7oIM"
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.Model.list()

Example with the openai Node.js package:

1
2
3
4
5
6
7
8
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
  organization: "org-HW93VY7Oko7ptiKrGabG7oIM",
  apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(configuration);
const response = await openai.listEngines();

Organization IDs can be found on your Organization settings page.