Skip to main content
Portkey’s REST API provides direct HTTP access to 250+ LLMs with production-grade routing, fallbacks, and observability. Use it from any programming language or tool that can make HTTP requests.

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

For self-hosted gateway:

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:
Response (Server-Sent Events):

Switching Providers

Change providers by updating the header:

Advanced Routing

Using Configs

Pass a config object via header:
Or use a saved config ID:

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:
Common status codes:
  • 400 - Bad request
  • 401 - Unauthorized (invalid API key)
  • 429 - Rate limit exceeded
  • 500 - Server error
  • 502 - Bad gateway
  • 503 - Service unavailable

Headers Reference

*Either virtual-key OR (provider + Authorization) required

Best Practices

Always use virtual keys instead of raw provider keys for better security:
Set up fallback providers for production reliability:
Use caching to reduce costs and improve latency:
Always include metadata for debugging and analytics:
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.