Skip to main content
The Portkey AI Gateway is fully compatible with the OpenAI API surface. You can point any OpenAI SDK client at the gateway URL and it will route your requests through the gateway without any other code changes. This works for both the official OpenAI SDKs and the Portkey-native SDK (portkey-ai), which adds convenience helpers for headers and configs.

Installation

1

Start the gateway

Run the gateway locally or use Portkey Cloud.
The gateway listens at http://localhost:8787/v1.
2

Install the SDK

Basic setup

When using the local gateway, you pass your provider API key directly to the SDK. When using Portkey Cloud, set a Portkey API key and use virtual keys to manage your provider credentials centrally.

Attaching a config for routing and guardrails

Configs let you define routing rules, retries, fallbacks, and guardrails as a JSON object. Attach a config to the client to apply it to every request.

Using Portkey Cloud (hosted gateway)

When using the hosted gateway at https://api.portkey.ai/v1, authenticate with a Portkey API key and reference your provider credentials through virtual keys.

Real-world use case: fallback between providers

Route to Anthropic Claude if OpenAI is unavailable, with automatic retries.
Store your config as a saved config in the Portkey dashboard and reference it by ID with config="cfg_xxxx" to keep your application code clean.