Skip to main content
Available on all Portkey plans.
Configs streamline your Gateway management, enabling you to programmatically control various aspects like fallbacks, load balancing, retries, caching, and more. A configuration is a JSON object that can be used to define routing rules for all the requests coming to your gateway. You can configure multiple configs and use them in your requests.

Creating Configs

Navigate to the ‘Configs’ page in the Portkey app and click ‘Create’ to start writing a new config.

Using Configs

Configs are supported across all integrations.
  • Through the config parameter of the Portkey SDK client(Directly or via frameworks)
  • Through the config headers in the OpenAI SDK
  • Via the REST API through the x-portkey-config header

Applying Gateway Configs

Gateway configs allow you to unlock the gateway superpowers of Portkey. You can create a config in the UI and attach it’s config id in the OpenAI client.
  • NodeJS
  • Python
  • OpenAI NodeJS
  • OpenAI Python
  • cURL
const portkey = new Portkey({
    apiKey: "PORTKEY_API_KEY",
    config: "pc-***" // Supports a string config id or a config object
});
If you want to attach the configuration to only a few requests instead of modifying the client, you can send it in the request headers for OpenAI or in the config parameter while using the Portkey SDK.
Note: If you have a default configuration set in the client, but also include a configuration in a specific request, the request-specific configuration will take precedence and replace the default config for that particular request.
  • NodeJS
  • Python
  • OpenAI NodeJS
  • OpenAI Python
portkey.chat.completions.create({
  messages: [{role: "user", content: "Say this is a test"}],
  model: "gpt-3.5-turbo"
}, {config: "pc-***"})
You can also add the config JSON as a string instead of the slug.

Setting Default Configs on API Keys

You can attach a default config directly to an API key, which means all requests made with that key will automatically use the specified config without needing to include it in each request. This is particularly useful for:
  • Integrations that don’t support custom headers (like Open WebUI, LibreChat, and other OpenAI-compatible interfaces)
  • Enforcing organization-wide governance policies without requiring code changes
  • Centralized configuration management where all applications using a specific API key share the same routing, fallbacks, and caching rules
When you attach a default config to an API key, every request made with that key automatically applies the config’s settings (routing, fallbacks, caching, etc.), even if the application doesn’t send the x-portkey-config header. To set a default config on an API key:
  1. Navigate to API Keys in the Portkey dashboard
  2. Create a new API key or edit an existing one
  3. In the API key settings, select a config from the Default Config dropdown
  4. Save the API key
See the Default Configs documentation for detailed instructions and use cases.
If you specify a config in a request (via headers or SDK parameters), it will override the default config for that specific request. The default config only applies when no config is specified in the request itself.

Configs in Logs

Portkey shows your Config usage smartly on the logs page with the Status column and gives you a snapshot of the Gateway activity for every request. Read more about the status column here. You can also see the ID of the specific Config used for a request separately in the log details, and jump into viewing/editing it directly from the log details page.

Config Object Documentation

Find detailed info about the Config object schema, and more examples:

Config Schema