Authentication
The OpenAI API uses API keys for authentication. Visit your API Keys page to retrieve the API key you'll use in your requests.
Remember that your API key is a secret! Do not share it with others or expose it in any client-side code (browsers, apps). Production requests must be routed through your own backend server where your API key can be securely loaded from an environment variable or key management service.
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 curl https://api.openai.com/v1/models \
2 -H 'Authorization: Bearer YOUR_API_KEY' \
3 -H 'OpenAI-Organization: YOUR_ORG_ID'
Example with the openai
Python package:
1 import os
2 import openai
3 openai.organization = "YOUR_ORG_ID"
4 openai.api_key = os.getenv("OPENAI_API_KEY")
5 openai.Model.list()
Example with the openai
Node.js package:
1 import { Configuration, OpenAIApi } from "openai";
2 const configuration = new Configuration({
3 organization: "YOUR_ORG_ID",
4 apiKey: process.env.OPENAI_API_KEY,
5 });
6 const openai = new OpenAIApi(configuration);
7 const response = await openai.listEngines();
Organization IDs can be found on your Organization settings page.