Skip to content
Docs

Header-Based Routing

Header-Based Routing lets you direct gateway requests to different upstream targets based on the values of HTTP request headers — without changing the request URL or requiring separate API keys. It is the foundation for multi-tenant routing, blue-green deployments, environment separation (production vs. staging), and feature flags for gradual rollouts.

Example scenarios:

Use Case Header Routes to
Multi-tenant routing X-Tenant: acme-corp Acme’s private LLM endpoint
Environment separation X-Environment: staging Staging model provider
A/B model testing X-Experiment: gpt4 GPT-4o provider
Regional routing X-Region: eu EU-hosted model endpoint
Type Description Example
Exact Header value must match exactly X-Tenant: acme-corp
Glob Header value matches a glob pattern X-Tenant: acme-*
Regex Header value matches a regular expression X-Tenant: ^(acme|globex)$
  • all — Every header condition on the route must be satisfied for the route to match.
  • any — Any single condition is sufficient to match.

The match type is inferred from the pattern: a value wrapped in slashes (/^(acme|globex)$/) is a case-insensitive regular expression, a value containing * is a glob, and anything else is an exact, case-insensitive match.

Header conditions are attached to a gateway route; each route has its own upstream URL. To send different header values to different targets, create one gateway route per target.

  1. Incoming request arrives with its path and headers.
  2. AgentWatch evaluates gateway routes in priority order (higher number first).
  3. A route whose path matches but whose header conditions do not is skipped.
  4. The first route whose path and header conditions both match wins; the request goes to that route’s upstream URL.

Header conditions are stored in the route’s metadata:

{
"pathPattern": "/v1/chat/completions",
"upstreamUrl": "https://acme-prod.internal.company.com",
"metadata": {
"matchHeaders": {
"X-Tenant": "acme-corp",
"X-Environment": "prod-*"
},
"matchHeaderMode": "all"
}
}

This route receives any request that has both X-Tenant: acme-corp AND X-Environment starting with prod-.

Step-by-Step: Setting Up Header-Based Routing

Section titled “Step-by-Step: Setting Up Header-Based Routing”
  1. Navigate to Settings → Gateway Routes.
  2. Create one gateway route per target, each with its own Upstream URL.
  3. On each route’s Header Match tab, click Add Condition and enter a Header Name (e.g. X-Tenant) and a Value pattern.
  4. Choose whether all or any of the conditions must match.
  5. Save. The first route whose path and header conditions match wins.

Header-based routing (this section) operates at the gateway route level — it directs traffic to different upstream hosts. Tenant Routing Rules (section 7.12) operate at the request processing level — they modify, enrich, or redirect request content before sending it to the LLM. Both can be used together.