Skip to main content
Payload Injection allows you to apply default parameters or force override specific fields in model request payloads globally. This is useful for setting consistent behavior across models, injecting metadata, or enforcing organizational policies without modifying client code.

Overview

Payload injection operates in two modes:
  • Default: Only sets parameters if they are missing in the original request
  • Override: Always overwrites parameters, even if present in the original request
Rules are defined in config.yaml and apply to models matching specific patterns and protocols.
Payload injection happens after request translation but before the request is sent to the provider, ensuring compatibility with all supported protocols.

Configuration

Add the payload section to your config.yaml:

Rule Structure

Model Matching

Each rule specifies which models it applies to:
Pattern Syntax:
  • * matches zero or more characters
  • gemini-* matches gemini-2.5-pro, gemini-3-flash, etc.
  • gpt-*-turbo matches gpt-3.5-turbo, gpt-4-turbo, etc.
  • * matches all models
Protocol Matching: When specified, rules only apply to requests using that protocol:
  • openai - OpenAI-compatible endpoints
  • gemini - Google Gemini API
  • claude - Anthropic Claude API
  • vertex - Google Vertex AI
If protocol is omitted, the rule applies to all matching models regardless of protocol.

Parameters

Parameters use dot notation to specify nested JSON paths:

Default vs Override

Default Mode

Defaults only set parameters if they are missing from the original request:
Behavior:

Override Mode

Overrides always overwrite parameters, regardless of their presence:
Behavior:
Use default for convenience parameters and override for enforcing policies or injecting system metadata.

Common Use Cases

1. Enforce Thinking Budget for Gemini

Ensure all Gemini reasoning models use a minimum thinking budget:

2. Set Default Temperature Across All Models

3. Inject User Metadata for Tracking

Track all requests with organizational metadata:

4. Enforce Context Limits

Prevent clients from requesting excessive tokens:

5. Provider-Specific Configurations

Apply different defaults per provider:

Advanced Patterns

Multi-Protocol Rules

Apply the same parameters to multiple protocols:

Conditional Parameters by Model Tier

Different configurations for different model tiers:

Nested Configuration Objects

Build complex nested configurations:

Debugging

Enable Debug Logging

Set debug: true in config.yaml to see payload injection logs:
You’ll see output like:

Verify Parameters

Use the Management Dashboard to inspect outgoing requests:
  1. Open http://localhost:18080/dashboard
  2. Navigate to Request Inspector
  3. View the Modified Payload section
Send a test request and verify the injected parameters:
Check the debug logs to confirm injection occurred.

Precedence Rules

Default Rules

For default mode:
  1. First write wins per field across all matching rules
  2. If a field exists in the original request, it is never overwritten
  3. Rules are evaluated in the order they appear in config.yaml

Override Rules

For override mode:
  1. Last write wins per field across all matching rules
  2. Fields are always overwritten, even if present in the original request
  3. Rules are evaluated in the order they appear in config.yaml

Combined Example

Protocol-Specific Paths

Different protocols use different JSON structures. switchAILocal handles this automatically:

Gemini API (Standard)

Parameters apply to the root payload:

Gemini CLI API

Parameters are nested under request:
switchAILocal automatically detects the protocol and adjusts paths accordingly. You don’t need separate rules for Gemini API vs Gemini CLI.

OpenAI API

Claude API

Limitations

  • Array parameters are not supported for partial updates (entire array is replaced)
  • Cannot delete fields, only add or overwrite
  • No conditional logic within a single rule (use multiple rules instead)
  • Parameters must be valid JSON types (string, number, boolean, object)

See Also