Use the AI Gateway as a drop-in replacement for the OpenAI SDK in Python and JavaScript.
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.
from portkey_ai import Portkeyclient = Portkey( provider="openai", Authorization="sk-***" # your provider API key)response = client.chat.completions.create( messages=[{"role": "user", "content": "Hello!"}], model="gpt-4o-mini")print(response.choices[0].message.content)
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.
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.