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
| Field | Type | Description |
|---|---|---|
provider | string | Provider name (e.g., “openai”, “anthropic”, “azure-openai”) |
api_key | string | Provider API key |
virtual_key | string | Portkey virtual key for secure key management |
custom_host | string | Custom endpoint URL for provider |
Strategy Configuration
| Field | Type | Description |
|---|---|---|
strategy.mode | string | Routing mode: “single”, “fallback”, “loadbalance”, “conditional” |
strategy.on_status_codes | number[] | Status codes that trigger fallback (fallback mode only) |
strategy.conditions | array | Conditional routing rules (conditional mode only) |
strategy.default | string | Default target for conditional routing |
Retry Configuration
| Field | Type | Description |
|---|---|---|
retry.attempts | number | Maximum retry attempts (0-5) |
retry.on_status_codes | number[] | Status codes that trigger retry |
retry.use_retry_after_header | boolean | Respect provider’s Retry-After header (default: false) |
Retry attempts are capped at 5 to prevent excessive retry loops. The gateway uses exponential backoff between retries.
Cache Configuration
| Field | Type | Description |
|---|---|---|
cache.mode | string | ”simple” or “semantic” |
cache.max_age | number | Cache TTL in milliseconds |
Timeout Configuration
| Field | Type | Description |
|---|---|---|
request_timeout | number | Request timeout in milliseconds |
src/handlers/retryHandler.ts:4-50
Guardrails Configuration
| Field | Type | Description |
|---|---|---|
input_guardrails | array | Input validation rules executed before provider request |
output_guardrails | array | Output validation rules executed after provider response |
before_request_hooks | array | Custom hooks executed before request |
after_request_hooks | array | Custom hooks executed after response |
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:- 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
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
-
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
- Valid Provider - Provider must be in the list of supported providers
- Valid Strategy Mode - Must be one of: single, loadbalance, fallback, conditional
- Valid Cache Mode - Must be “simple” or “semantic”
- Custom Host Format - Must be a valid URL if provided
src/middlewares/requestValidator/schema/config.ts:11-179
Passing Configs
Via Header
Via SDK
Via Environment
Configs can also be stored inconf.json at the gateway root for system-wide defaults.
Config Conversion
The gateway automatically converts between snake_case and camelCase:src/handlers/handlerUtils.ts:1007-1165
Override Parameters
You can override request parameters usingoverride_params:
Forward Headers
Specify which request headers should be forwarded to the provider:OpenAI Compliance
For strict OpenAI API compliance, setstrict_open_ai_compliance:
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.