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
- Local (npx)
- Portkey Cloud
http://localhost:8787/v1.2
Install the SDK
- portkey-ai (Python)
- openai (Python)
- openai (JavaScript)
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 athttps://api.portkey.ai/v1, authenticate with a Portkey API key and reference your provider credentials through virtual keys.