OpenAI API Authentication
Use an API key through HTTP Bearer authentication. The important operational decisions are where the key is stored and which project receives the requests.
textAuthorization: Bearer YOUR_API_KEY
#Keep the key server-side
Set OPENAI_API_KEY through your local secret configuration or deployment secret manager. Do not place a real key in browser code, committed files, logs or a shared prompt.
bashexport OPENAI_API_KEY="YOUR_API_KEY"
powershell$env:OPENAI_API_KEY="YOUR_API_KEY"
These values are placeholders. Follow the operating system's secure configuration practice for actual credentials.
#Project and organization context
Where required by the key/account configuration, requests can include OpenAI-Organization and OpenAI-Project headers. Confirm the intended environment instead of allowing development and production usage to become mixed.
The official SDK reads the key from the environment by default:
pythonfrom openai import OpenAI client = OpenAI(timeout=20.0)
Constructing a client does not verify that the key has access to the intended model. Treat authentication failures, project authorization and quota/billing failures as distinct diagnostics.