OpenAI API Key
Environment Variable (Recommended)
The most secure way to provide your API key is through theOPENAI_API_KEY environment variable:
Using python-dotenv
For local development, use python-dotenv to load your API key from a.env file:
1
Install python-dotenv
2
Create .env file
Create a
.env file in your project root:3
Load environment variables
Direct API Key (Not Recommended)
You can pass the API key directly, but this is not recommended for production:Get an API Key
You can obtain an API key from the OpenAI Platform.Azure OpenAI Authentication
Azure OpenAI supports two authentication methods: API keys and Azure Active Directory (Azure AD).API Key Authentication
Use theAZURE_OPENAI_API_KEY environment variable: