Overview
The REST API offers:- Universal Access: Use from any language (Python, Go, Ruby, PHP, etc.)
- OpenAI-Compatible: Same endpoints and request/response format
- 250+ LLMs: Access any provider through unified API
- Simple Integration: Just HTTP headers and JSON payloads
- Production Features: Fallbacks, caching, retries, and guardrails
Base URL
Authentication
Portkey uses HTTP headers for authentication and configuration:Required Headers
Provider Authentication
Choose one method:Quick Start
1
Get Your API Keys
Sign up at Portkey and get your API key. Add provider keys as Virtual Keys.
2
Make Your First Request
Chat Completions
Basic Request
Response
Streaming
Enable streaming with"stream": true:
Switching Providers
Change providers by updating the header:Advanced Routing
Using Configs
Pass a config object via header:Fallback Example
Load Balancing
Retries
Caching
Simple Caching
Semantic Caching
Metadata and Tracing
Add custom metadata:Other Endpoints
Completions (Legacy)
Embeddings
Image Generation
Audio Transcription
Text to Speech
Language Examples
Python (requests)
Node.js (fetch)
Go
Ruby
PHP
Error Responses
Portkey returns standard HTTP status codes:400- Bad request401- Unauthorized (invalid API key)429- Rate limit exceeded500- Server error502- Bad gateway503- Service unavailable
Headers Reference
*Either
virtual-key OR (provider + Authorization) required
Best Practices
Use Virtual Keys
Use Virtual Keys
Always use virtual keys instead of raw provider keys for better security:
Configure Fallbacks
Configure Fallbacks
Set up fallback providers for production reliability:
Enable Caching
Enable Caching
Use caching to reduce costs and improve latency:
Add Metadata
Add Metadata
Always include metadata for debugging and analytics:
Handle Errors
Handle Errors
Implement proper error handling for all status codes.
Complete Production Example
Resources
The REST API is perfect for integrating Portkey into any application, regardless of programming language.