Setup guide
Set up your gateway
Your first request works. This guide covers the five things that turn Leanroute from a pass-through into a gateway that protects your budget and your data. Each takes a few minutes, and each section says what is already on by default.
In this guide
Not sent your first request yet? Start on your dashboard: choose a plan, create an API key, and run the sample request.
1. Set spend caps
Default: no limits. Do this first. A spend cap stops the next request once you reach it, so a stuck agent or a leaked key cannot run up a bill overnight.
- Go to Dashboard, Settings, card Throttle limits.
- Set a monthly spend cap at roughly 1.5 to 2 times what you expect to spend, and a daily spend cap at about 3 times a normal day.
- Optional: set requests per minute a little above your real peak.
- For risky keys (an experimental agent, a contractor, CI), add tighter caps on that key under Dashboard, API keys. The stricter of the key and org limit wins.
Caps count traffic on your own provider keys too, and you get an email at 80% of a cap. When one is hit, requests return 402 spend_cap_exceeded; don't retry those in a loop. More in Spend caps and rate limits.
2. Turn on guardrails
Default: off. Guardrails stop personal data and credentials from reaching a provider, and can check the model's answers on the way back.
- Go to Dashboard, Guardrails.
- Enable PII redaction and Secret detection in preview mode for a week. Preview only logs matches, so nothing breaks while you see what they would catch.
- Watch the
x-gateway-guardrails-triggeredresponse header and your logs for false positives, tune the severity threshold if needed, then let preview end. - Add Prompt injection if users type free text into your app, and the response-side rules (data exfiltration, profanity, language gate) for customer-facing chat. Response-side rules check non-streaming answers only.
- For your own patterns, such as internal project names or account ID formats, add block or redact rules under Dashboard, Settings, card Guardrails.
More in LLM guardrails and on the guardrails page.
3. Decide on routing
Default: you get exactly the model you asked for, with automatic failover to an equivalent model if the provider is down. Cheaper-model swaps are off.
- Send real traffic for a few days first, and look at cost per provider on Dashboard, Usage.
- Under Dashboard, Settings, card Routing, set Cheaper-model swaps to On. Requests are then served by the cheapest model in the same quality tier. Requests with tools, MCP servers or images are never swapped.
- If only some vendors are approved, set Allowed providers (or Blocked providers). These apply to swaps and failover.
- To pin a single call to the exact model, send the header
x-gateway-routing: explicit.
Tiers are listed on /tiers. More in LLM routing with Leanroute.
4. Caching (already on)
Default: on, every plan. Identical and near-identical non-streaming requests are answered from cache for 15 minutes and billed at $0. Your cache is isolated from every other organization's.
- Nothing to set up. Check hits with the
x-gateway-cacheresponse header and the cache hit rate on your dashboard. - Streaming requests and requests with MCP servers are never cached.
- If prompts must never be stored, even for 15 minutes, turn on no-persistence mode under Dashboard, Settings, card Privacy & cache. That turns caching off for your organization.
More in Caching.
5. MCP tools (optional)
Default: no MCP servers allowed. If your app uses MCP tools, Leanroute runs the tool loop for any model, not only Claude. A server has to be on your allowlist before a request can use it.
- Add each MCP server URL under Dashboard, MCP.
- Pass
mcp_serversin a chat completion request. The gateway connects, runs the tools and returns one final answer.
More in MCP at the gateway.
6. Check it all works
Send one request and read the response headers. On a BYOK plan, use a model from a provider you have added a key for.
curl -sD - https://api.leanroute.dev/v1/chat/completions \
-H "Authorization: Bearer $LEANROUTE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"openai/gpt-5.6-luna","messages":[{"role":"user","content":"Say hi"}]}' \
-o /dev/null | grep -i x-gatewayx-gateway-providerandx-gateway-model: who answered.x-gateway-routed-from: present when a cheaper-model swap happened.x-gateway-cost-usd: what the request cost.x-gateway-cache: present on a cache hit. Send the same request twice to see it.x-gateway-guardrails-triggered: present when a guardrail matched.
Every header is described in the headers reference. Questions? Email support@leanroute.dev.