The LLM Gateway is in early access as a self-hosted service. Talk to your Runlayer contact before rolling it out broadly.
- Optimize cost with model routing — substitute models by rule (for example, serve
gpt-4.1requests withgpt-4o-mini), including across providers - Degrade, don’t deny — when a virtual key’s budget is spent, downgrade expensive models to cheaper ones instead of failing requests
- Support any AI client — Claude Code, Cursor, Codex, OpenAI/Anthropic SDKs, or any script that speaks either API
- Keep provider keys out of client hands — clients hold a Runlayer virtual key; provider API keys live only in the gateway
- See everything in Sessions — prompts, responses, per-call token usage, cost, and routing decisions, attributed to the real client and user
Managing keys, rules, and provider credentials
Virtual keys and routing rules live in the Runlayer backend and are managed in the app under Settings → LLM Gateway: create keys (shown once, with optional USD budgets) and maintain the ordered rule list (glob pattern → target model, always or only over budget). Gateways poll the backend and hot-apply changes within their sync interval (30s by default); revoked keys stop authenticating on the same cadence. Keys are stored and synced as SHA-256 hashes — plaintext exists only in the one-time reveal at creation. Spend is durable: gateways report per-call cost to the backend, accumulated spend survives restarts and is shared across gateway replicas, and each key’s current spend shows next to its budget in the settings page. Provider API keys (Anthropic, OpenAI, OpenAI-compatible) come from Settings → AI Providers — add a provider there and every synced gateway can serve its models within the same interval, no gateway config change needed.How it works
The gateway exposes two API surfaces:
Each request is authenticated with a virtual key (sent as
x-api-key or Authorization: Bearer, whichever the client already uses). The gateway then:
- Applies routing rules — first matching rule wins, and may substitute the provider and model
- Calls the upstream provider, translating between API dialects when the rule routes cross-provider (an Anthropic client routed to an OpenAI model still receives an Anthropic-shaped response, including streaming)
- Meters token usage and cost against the virtual key’s budget
- Emits the turn to Sessions
Routing rules
A rule matches the requested model with a glob pattern and substitutes the targetprovider/model; it applies always (default) or only over_budget. Rules are ordered — first match wins. For example:
The same shape works as inline
rules in the gateway config file for standalone/bootstrap use — { "model": "gpt-4.1", "to": "openai/gpt-4o-mini", "when": "always" }.
Spend is computed from response usage against the prices_per_mtok table in the gateway config (or provider-reported cost when available).
Latency
The gateway’s processing overhead — auth, routing, dialect handling, metering — is roughly 0.1ms per request (p50) and under 0.3ms at p99 (measured on loopback against a mock upstream). Session streaming happens off the request path. In practice the added latency is dominated by the network hop to wherever the gateway is deployed, so place it close to your clients or providers; both are negligible next to model response times.Client support
Any client that can point at a custom API base URL works with the gateway. The matrix below is verified against each client’s official docs. Use/anthropic for clients that speak the Anthropic Messages API and /openai/v1 for OpenAI-compatible clients (both Chat Completions and the Responses API are served).
Connecting clients manually
Point the client at the gateway and swap the provider API key for your Runlayer virtual key.Connecting clients via MDM
For managed fleets, distribute the same two settings — base URL and virtual key — through your MDM instead of asking users to configure anything:- Issue virtual keys scoped the way you want attribution to work (per team or per user).
- Push the configuration with the same MDM integrations used for AI Watch deployment and auto-provisioning — a managed environment profile (macOS) or policy (Windows) that sets
ANTHROPIC_BASE_URL,OPENAI_BASE_URL, and the corresponding API key variables for the clients you manage. - Traffic from every managed device now flows through the gateway with no per-user setup, and appears in Sessions attributed to the device’s user.
What you see in Sessions
Gateway conversations appear in Sessions like any other monitored client:- The session card shows the real client (detected from the request’s User-Agent — Claude Code, Cursor, an SDK, or the raw tool name for scripts) and the requested model, plus the user behind the virtual key
- The timeline shows each prompt and response, and a Model Call entry per request with token counts and cost
- When a routing rule substituted the model, the Model Call shows the routing explicitly:
claude-opus-4-8 → gpt-4o-mini
Configuration reference
The gateway is configured with a single JSON file. Values of the formenv.VAR are resolved from the environment at startup.