Header-Based Routing
What Is Header-Based Routing?
Section titled “What Is 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 |
Match Types
Section titled “Match Types”| 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)$ |
Match Modes
Section titled “Match Modes”- 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.
How Routing Is Evaluated
Section titled “How Routing Is Evaluated”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.
- Incoming request arrives with its path and headers.
- AgentWatch evaluates gateway routes in priority order (higher number first).
- A route whose path matches but whose header conditions do not is skipped.
- The first route whose path and header conditions both match wins; the request goes to that route’s upstream URL.
Configuration Example
Section titled “Configuration Example”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”- Navigate to Settings → Gateway Routes.
- Create one gateway route per target, each with its own Upstream URL.
- On each route’s Header Match tab, click Add Condition and enter a Header Name (e.g.
X-Tenant) and a Value pattern. - Choose whether all or any of the conditions must match.
- Save. The first route whose path and header conditions match wins.
Relationship to Tenant Routing Rules
Section titled “Relationship to Tenant Routing Rules”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.