Gateway Routes
What Are Gateway Routes?
Section titled “What Are Gateway Routes?”A Gateway Route is AgentWatch’s fundamental routing unit. It defines:
- Which inbound path to intercept (e.g.
/v1/chat/completions) - Which upstream target to forward matching requests to (a provider URL or load-balanced pool)
- How to transform headers, query parameters, and request body before forwarding
- How to protect the route with rate limits, IP allowlists/blocklists, circuit breakers, and timeouts
Every AI API call a developer makes to AgentWatch is matched against the gateway route table. Routes are evaluated in priority order — the first match wins.
How a Request Flows Through a Gateway Route
Section titled “How a Request Flows Through a Gateway Route”Developer API Call │ ▼┌─────────────────────────────────────────┐│ Route Matching (path + method) ││ First matching route wins │└──────────────┬──────────────────────────┘ │ ▼┌─────────────────────────────────────────┐│ Security Checks ││ • IP allowlist / blocklist ││ • Rate limit (token bucket per route) ││ • Circuit breaker — open? Fail fast │└──────────────┬──────────────────────────┘ │ ▼┌─────────────────────────────────────────┐│ Request Transforms ││ • Rewrite path ││ • Inject / remove headers ││ • Replace query parameters ││ • Modify request body (templates) │└──────────────┬──────────────────────────┘ │ ▼┌─────────────────────────────────────────┐│ Forward to Upstream Target ││ (HTTP / HTTPS; streaming supported) │└──────────────┬──────────────────────────┘ │ ▼┌─────────────────────────────────────────┐│ Response Transforms ││ • Inject / remove response headers │└──────────────┬──────────────────────────┘ │ ▼ Return to ClientRoute Configuration Fields
Section titled “Route Configuration Fields”| Field | Description | Example |
|---|---|---|
| Name | Human-readable label | Production OpenAI |
| Path Pattern | URL path to match (exact or glob) | /v1/chat/completions |
| Upstream URL | Upstream endpoint to forward to | https://api.openai.com |
| Priority | Evaluation order — higher number is evaluated first (0–100, default 0) | 10 |
| Enabled | Enable / disable without deleting | true |
| TTL (ms) | Route TTL in milliseconds (default 30000) | 30000 |
| Mode | proxied, enriched, or post-process |
proxied |
Route Modes
Section titled “Route Modes”| Mode | Description |
|---|---|
| Proxied | Standard pass-through. Request → upstream → response. Full streaming support. |
| Enriched | Capture the upstream LLM response, send it to a secondary AgentEnricher endpoint, then return the enriched result to the client. |
| Post-Process | Send to the AgentEnricher first, extract enriched content, inject it into a second LLM call, then return the final response. |
Request Transforms
Section titled “Request Transforms”Transforms modify requests before they are forwarded upstream. They use template variables that are resolved at request time:
| Variable | Resolves to |
|---|---|
{{route_name}} |
The matched route’s name |
{{route_id}} |
The matched route’s ID |
{{tenant_id}} |
The API key’s tenant ID |
{{path}} |
The request path |
{{method}} |
The request HTTP method |
{{model}} |
The model named in the request body |
Routes match on path pattern and header conditions only, not on HTTP method. To remove a path prefix before forwarding, use the route’s Rewrite tab (match / replace).
Path rewriting (Rewrite tab):
{ "match": "^/v1/", "replace": "/openai/v1/" }Header injection:
[{ "action": "addHeader", "key": "X-Custom-Tenant", "value": "{{tenant_id}}" }]Header removal:
[{ "action": "removeHeader", "key": "Authorization" }]Supported transform actions: addHeader, removeHeader, modifyHeader, addQueryParam, removeQueryParam, setBody, removeBody.
Rate Limiting Per Route
Section titled “Rate Limiting Per Route”Each route can have an optional token bucket, independent of global limits. A route has no limit unless maxRequests is set:
| Setting | Description | Default |
|---|---|---|
maxRequests |
Tokens in the bucket | None (no limit) |
windowMs |
Refill window in milliseconds | 60000 (1 min) when set from the console |
When the bucket is empty, the route returns 429 Too Many Requests with a Retry-After header.
IP Filtering Per Route
Section titled “IP Filtering Per Route”- Allowlist — Only IP addresses matching the CIDR ranges in this list may access the route. Empty = allow all.
- Blocklist — IP addresses matching these CIDR ranges are rejected with
403 Forbidden.
Blocklist is evaluated before allowlist. Both support CIDR notation (192.168.0.0/16).
Health Monitoring
Section titled “Health Monitoring”AgentWatch periodically sends HEAD requests to each route’s upstream target and tracks:
| State | Meaning |
|---|---|
healthy |
Responding within expected latency |
degraded |
Elevated latency or occasional errors |
unhealthy |
Auto-disabled after 6 consecutive failures; re-enabled after 3 successes |
View route health in Settings → Gateway Routes (open a route to see its health and analytics).
Step-by-Step: Create a Gateway Route
Section titled “Step-by-Step: Create a Gateway Route”- Navigate to Settings → Gateway Routes.
- Click Add Route.
- Set Name, Path Pattern, and Upstream URL.
- Set TTL (ms) (default 30000) and Priority (higher = evaluated first).
- (Optional) Under Request Transforms, add header injections or path rewrites.
- (Optional) Enable Rate Limiting and set a per-minute request cap.
- (Optional) Add IP Allowlist or Blocklist CIDR ranges.
- Click Save. The route is active immediately.
Gateway routes do not load-balance across upstreams. For distributing traffic across provider API keys, use the provider API Key load-balancing settings; for tiered model selection with failover, use Complexity Routing.
API Reference
Section titled “API Reference”| Method | Endpoint | Description |
|---|---|---|
| GET | /admin/gateway/routes |
List all routes |
| POST | /admin/gateway/routes |
Create a route |
| PUT | /admin/gateway/routes/:id |
Update a route |
| DELETE | /admin/gateway/routes/:id |
Delete a route |
| GET | /admin/gateway/health |
Route health statuses |
| POST | /admin/gateway/routes/:id/health/check |
Trigger on-demand health check |
| GET | /api/admin/gateway/openapi.json |
OpenAPI spec generated from routes |