Setup
Chat completions
Responses
Images
Audio
Video
Embeddings
Moderations
Batch & files
Models & health
Errors
Error Handling
Configuration Options
Type Hints
Best Practices
- Use
async withcontext managers for proper resource cleanup - Handle rate limits with exponential backoff
- Check credits before expensive operations
- Use streaming for real-time user experiences
- Store API keys securely (environment variables, not in code)