Skip to main content
Configs are the core mechanism for controlling how the Portkey AI Gateway processes requests. They define routing rules, retry policies, caching behavior, guardrails, and more.

Config Structure

A config is a JSON object that can be passed via headers or in the request body. Configs support both snake_case and camelCase keys.

Basic Config

Complete Config Example

Config Fields

Provider Configuration

Strategy Configuration

Retry Configuration

Retry attempts are capped at 5 to prevent excessive retry loops. The gateway uses exponential backoff between retries.
See Retries for detailed retry configuration.

Cache Configuration

Streaming requests are not cached. The cache middleware automatically skips streaming requests.
See Caching for detailed cache configuration.

Timeout Configuration

When a request exceeds the timeout, the gateway returns a 408 status with a timeout error. Source: src/handlers/retryHandler.ts:4-50

Guardrails Configuration

See Guardrails for detailed guardrail configuration.

Provider-Specific Fields

Azure OpenAI

Google Vertex AI

Vertex AI requires either vertex_project_id or vertex_service_account_json along with vertex_region.

AWS Bedrock

OpenAI

Config Inheritance

Configs support inheritance where child targets inherit properties from parent configs:
Inheritance Rules:
  • Child configs override parent configs for the same field
  • Arrays (like hooks and guardrails) are merged, not replaced
  • Nested targets can define their own strategies
Source: src/handlers/handlerUtils.ts:470-644

Config Validation

The gateway validates all configs using Zod schemas. Invalid configs are rejected with a 400 status code.

Validation Rules

  1. Provider + API Key OR Strategy + Targets - Configs must have either:
    • A provider and api_key, OR
    • A strategy with targets, OR
    • Cache/retry/timeout settings
  2. Valid Provider - Provider must be in the list of supported providers
  3. Valid Strategy Mode - Must be one of: single, loadbalance, fallback, conditional
  4. Valid Cache Mode - Must be “simple” or “semantic”
  5. Custom Host Format - Must be a valid URL if provided
Source: src/middlewares/requestValidator/schema/config.ts:11-179

Passing Configs

Via Header

Via SDK

Via Environment

Configs can also be stored in conf.json at the gateway root for system-wide defaults.

Config Conversion

The gateway automatically converts between snake_case and camelCase:
Source: src/handlers/handlerUtils.ts:1007-1165

Override Parameters

You can override request parameters using override_params:
Override params are merged with the request body, with override params taking precedence.

Forward Headers

Specify which request headers should be forwarded to the provider:
The gateway automatically filters out Portkey-specific headers (prefixed with x-portkey-) from forwarded headers.

OpenAI Compliance

For strict OpenAI API compliance, set strict_open_ai_compliance:
This removes provider-specific fields from responses that aren’t part of the OpenAI spec.

Best Practices

Version Your Configs

Store configs in version control to track changes and enable rollbacks.

Use Virtual Keys

Use virtual keys instead of hardcoding API keys for better security.

Test Configs Locally

Test config changes locally before deploying to production.

Monitor Config Performance

Track metrics for different configs to optimize routing and retries.

Next Steps

Routing

Learn about routing strategies and modes.

Guardrails

Configure input and output validation.

Caching

Optimize performance with response caching.

Load Balancing

Distribute load across providers and keys.