Overview
OpenAI is one of the leading AI providers, offering powerful language models (GPT-4, GPT-3.5, o1), image generation (DALL-E), speech (Whisper, TTS), and more. Portkey provides full support for all OpenAI capabilities. Base URL:https://api.openai.com/v1
Supported Features
- ✅ Chat Completions (including streaming)
- ✅ Completions (legacy)
- ✅ Embeddings
- ✅ Image Generation (DALL-E)
- ✅ Image Editing
- ✅ Text-to-Speech (TTS)
- ✅ Speech-to-Text (Whisper transcription)
- ✅ Audio Translation
- ✅ Realtime API (WebSocket)
- ✅ Function Calling & Tools
- ✅ Vision (GPT-4 Vision)
- ✅ Batch API
- ✅ Fine-tuning
- ✅ File Operations
Quick Start
Chat Completions
Streaming Responses
Popular Models
| Model | Context Window | Description | Best For |
|---|---|---|---|
gpt-4o | 128K tokens | Latest GPT-4 Omni model | General purpose, multimodal |
gpt-4o-mini | 128K tokens | Faster, cost-effective GPT-4 | High-volume tasks |
gpt-4-turbo | 128K tokens | Enhanced GPT-4 | Complex reasoning |
gpt-3.5-turbo | 16K tokens | Fast and efficient | Simple tasks, high throughput |
o1-preview | 128K tokens | Advanced reasoning | Math, science, coding |
o3-mini | 128K tokens | Efficient reasoning | Balanced performance |
text-embedding-3-large | 8K tokens | Latest embeddings | Semantic search, RAG |
dall-e-3 | N/A | Image generation | High-quality images |
whisper-1 | N/A | Speech-to-text | Transcription |
tts-1 | N/A | Text-to-speech | Voice generation |
Configuration Options
Headers
| Header | Description | Required |
|---|---|---|
Authorization | OpenAI API key (Bearer token) | Yes |
openai_organization | Organization ID | No |
openai_project | Project ID | No |
openai_beta | Beta feature flags | No |
Advanced Features
Function Calling
Vision (GPT-4 Vision)
Embeddings
Image Generation (DALL-E)
Text-to-Speech
Speech-to-Text (Whisper)
Fallback Configuration
Use Anthropic as fallback for OpenAI:Load Balancing
Distribute requests between OpenAI and Azure OpenAI:Batch API
Error Handling
Request & Response Format
Request
Response
Best Practices
- Use streaming for long responses to improve user experience
- Implement retry logic with exponential backoff for rate limits
- Cache embeddings to reduce costs and latency
- Use gpt-4o-mini for high-volume, simpler tasks
- Set max_tokens to control costs and response length
- Use system messages to guide model behavior consistently
- Implement fallbacks to other providers for reliability
Pricing
For up-to-date OpenAI pricing, visit:OpenAI Pricing
View detailed pricing for all OpenAI models
Related Resources
Azure OpenAI
Use OpenAI models through Azure
Fallback Routing
Set up fallbacks from OpenAI
Caching
Cache OpenAI responses
Function Calling
Advanced function calling guide