Skip to main content

Provider Routing

By default, the Router distributes requests across healthy providers using round-robin with automatic failover. X-0G-Provider-* request headers let you override this when you need specific behavior.

Default Behavior

If you send no routing headers, the Router:

  1. Picks a healthy provider for the requested model
  2. Retries on the next healthy provider if the first returns an error
  3. Returns the response — or a 503 if every provider failed

This is the recommended path for most applications.

Routing surfaces

The Router accepts routing preferences from two surfaces. In priority order:

PrioritySurfaceEndpointsStatus
1X-0G-Provider-* request headersAll inference endpoints (JSON, multipart, async)Canonical
2JSON body provider: {…} objectJSON endpoints only (/v1/chat/completions, /v1/messages, /v1/images/generations, /v1/async/images/generations)Deprecated — kept for back-compat

Headers and body are merged field-by-field; when the same field is set on both, the header wins. Multipart endpoints (/v1/audio/transcriptions, /v1/images/edits, /v1/async/images/edits) have no body routing surface — headers are the only way to control routing there.

The JSON body provider object is deprecated

New code should use X-0G-Provider-* headers. The body surface still works today for back-compat but will be phased out in a future release. Headers are the only routing surface that works uniformly across JSON, multipart, and async endpoints.

Routing Strategies

curl https://router-api.0g.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-YOUR_API_KEY" \
-H "X-0G-Provider-Sort: latency" \
-d '{
"model": "zai-org/GLM-5-FP8",
"messages": [{"role": "user", "content": "Hello"}]
}'

Routes to the provider with the lowest recently-observed latency for this model.

Header Reference

HTTP header names are case-insensitive per RFC 7230 — X-0G-Provider-Address and x-0g-provider-address are equivalent.

HeaderValuesDescription
X-0G-Provider-Addresson-chain address (0x…)Pin the request to a specific provider. Implies Allow-Fallbacks: false unless overridden.
X-0G-Provider-Sortlatency | priceSort strategy when no address is pinned. Ignored if X-0G-Provider-Address is set.
X-0G-Provider-Trust-Modeverified | privateRestrict provider selection to a trust tier — see Trust modes.
X-0G-Provider-Allow-Fallbackstrue | falseAllow cross-provider retry on failure. Lenient: anything other than true/false is treated as unset and defers to the default.

Defaults: Allow-Fallbacks is true normally, and false when X-0G-Provider-Address is set.

Trust modes

X-0G-Provider-Trust-Mode restricts selection by the provider's verification mode:

ValueRoutes toGuarantee
verifiedTeeML and TeeTLS providersVerifiable execution — the response provably came from the real model.
privateTeeML providers onlyVerifiability and privacy — the model itself runs inside the TEE, so prompts never leave the enclave.

verified is a floor, not an exact match: TeeML (private-tier) providers also satisfy a verified request, since running the model inside the TEE gives you everything TeeTLS does and more. Values other than verified/private are rejected with 400 invalid_trust_mode. Omit the header for no trust-tier restriction (the default).

Discovering Provider Addresses

List the providers serving a model with GET /v1/providers?model_id=… — see Models.

  • Principles — why failover is the default
  • Errors — what 502 and 503 mean for routing