Endpoint routing chooses between the upstream endpoints of one model. A
gateway.yaml model with upstreams[] has several, and they are balanced by router.strategy. A model registered through the console has one endpoint per enabled provider key on its account. Those keys are not balanced: they are tried in the order you set (prioritized keys first, fallback keys last), router.strategy and sticky sessions do not apply, and a key the provider refuses with 401, 402, 403 or 429 is skipped for the next one before anything reaches the client. To spread traffic across different models, use a routing config.
Endpoint routing
The default strategy applies to every request, whatever config it carries. These are the built-in defaults. The shipped container image overrides some of them (see Self-host):gateway.yaml
strategy (except score), health_interval, failure_threshold, cooldown, prefix_bytes and session_ttl in the administration console’s settings (Router section); the other fields are gateway.yaml only.
Sticky sessions
When a request carries anX-Session-Id header (or a user field in the body), the router remembers the endpoint that served that session for session_ttl and prefers it on later requests, under any strategy. If the endpoint is no longer usable, the session is remapped. On a virtual model, the same key also keeps a session on one side of a canary split.
Upstream health
- Ejection. An endpoint is taken out of rotation after
failure_thresholdconsecutive failures, or when its health average falls belowhealth_threshold. Connection errors, timeouts,5xx,429,408and401/402/403from the provider count as failures; other4xxresponses reject what the caller sent and do not. - Window. The ejection lasts
cooldown, multiplied by the number of ejections since the last success, up tomax_ejection_duration. When the provider states its own wait (Retry-After) andrespect_retry_afteris on, that wait is used instead, unescalated. - Recovery. Every
health_intervalthe gateway probes ejected endpoints withGET /v1/models. One that answers comes back atrestore_health, so it earns traffic back instead of taking its old share at once. A real success clears the escalation. - Failover. With several endpoints, a request that fails before any byte reaches the client moves to the next endpoint. If every endpoint is ejected, the request fails immediately with
provider_unavailable.
gateway.yaml:
healthy, ejected_until, inflight, consecutive_fails, score and latency averages) and the last hour’s request count, error rate and p95 latency per model. It requires the analytics permission in the workspace.
Routing configs
A routing config picks among models. Create one under Gateway → Routing, or with the API; the full schema, retry policy and per-target settings are on Virtual models.?workspace_id=<id>. Configs belong to one workspace and serve requests made in it.
Routing strategies
For every strategy exceptconditional, a target’s when still filters: targets whose when does not match are removed before the plan is made.
- Fallback
- Canary
- Conditional
- Latency
- Least busy
- Usage based
- Complexity (Auto Routing)
- Single
Try targets in order. A target is retried per
retry, then the request moves to the next target on a status in fallback_status_codes (by default 400 401 403 404 408 413 422 429 500 502 503 504, plus the retry codes).Using a routing config
A config applies to a request in one of three ways, in this order: the request’smodel is the name of a config that has model_types or is an Auto Routing (complexity) config (a virtual model), the X-ManyLayers-Config header names a config by id or name, or the team’s default_config_id applies. A config called by name suppresses the header. An unknown or disabled config in the header returns 400 unknown_config. A config selected by header must serve the endpoint being called, or the request is refused with 400 invalid_request; a team default that does not serve it is ignored.
X-ManyLayers-Config, X-ManyLayers-Routing-Strategy, X-ManyLayers-Routing-Model-Order and X-ManyLayers-Target.
Config management API
All routes are onhttps://app.manylayers.io and need the routing permission in the workspace (gateway.routing.read to read, gateway.routing.manage to change).