1. OpenAI API Authentication Instructions
The OpenAI API requires the use of an API key for authentication to ensure the security and legitimacy of the requests. The API key serves as the key for communicating with OpenAI services, and it needs to be provided every time a request is sent to indicate your identity.
2. Obtaining the OpenAI API Key
To obtain your OpenAI API key, please log in to the OpenAI dashboard and navigate to the key management page. Here, you can create a new API key, manage, and revoke existing API keys.
3. Adding the API Key in the HTTP Header
When making API requests to OpenAI, you need to add the Authorization
field in the HTTP request header, with its value being Bearer
followed by your API key. Below is an example of sending a request using the curl command:
curl "https://api.openai.com/v1/endpoint" \
-H "Authorization: Bearer OPENAI_API_KEY"
Please replace OPENAI_API_KEY
with your actual API key.
4. Using API Keys for Multiple Organization Members
If you are a member of multiple organizations and want to specify which organization's usage statistics the API requests should be attributed to, you can carry another field OpenAI-Organization
in the HTTP request header. The value of this field should be the ID of the organization to which you want the usage statistics to be attributed.
Here's an example of a curl command specifying the organization ID:
curl "https://api.openai.com/v1/endpoint" \
-H "Authorization: Bearer OPENAI_API_KEY" \
-H "OpenAI-Organization: YOUR_ORG_ID"
Please replace OPENAI_API_KEY
and YOUR_ORG_ID
with your actual API key and your organization's ID.
Tip: Always ensure the security of your API key and organization ID, and avoid disclosing them in any publicly accessible places, especially in client-side code. If the API key is leaked, it could lead to misuse of the service or unexpected charges. Protect your API key as you would protect your password.