An LLM gateway is the service between OpenClaw and the models that answer. OpenClaw sends a prompt. The gateway picks a real model, calls it, and returns the reply. You keep one base URL and one key. The gateway holds vendor keys, price rules, and the fallback list.
A single model string is enough on day one. It gets awkward when heartbeats should stay cheap, coding should use a stronger model, and private notes should stay local. An LLM router makes those choices in one place. This guide covers the proxy setup, the rules that save money, and when you should skip the extra process.
What an LLM Gateway Does for OpenClaw
An LLM gateway accepts one request format, usually an OpenAI-compatible chat call, and forwards it to Anthropic, OpenAI, Google, a smaller host, or a local server. OpenClaw only needs a provider id, a model id, and a URL that answers.
- Aliases. You call
fast-chatorstrong-chat. The map points those names at this month's model. A rename is one edit, not a sweep of every OpenClaw file. - Fallbacks. If the first model rate-limits or times out, the gateway tries the next one and still returns a normal reply.
- Spend logs. You see which job burned tokens, including a heartbeat that quietly hit a frontier model.
- An audit trail. The log shows the model id that actually answered when two providers sit in the list.
OpenClaw already has primary and fallback fields. A gateway does not replace them. Use those fields when the assistant should switch among providers it already knows. Use a gateway when several apps should share the same routes, or when alias names should survive vendor changes. Primary and fallbacks still live in the OpenClaw model config.
LLM Router vs a Single Default Model
A single default is enough when you have one provider key, one quality bar, and one bill. Set primary, add one fallback on a different provider, and stop. Stay there until a bill, an outage, or a privacy rule forces a change.
Add an LLM router when at least one of these is true:
- Two cost tiers. Short checks and long writing should not share a price.
- Two privacy tiers. Private files stay on a local LLM. Public research can use a hosted model.
- More than one client. Another script or agent should use the same routes as OpenClaw.
- Frequent model tests. A new id should be a gateway edit, not a restart on every box.
If none of those are true, skip the router. It is another process that can go down, and then your own proxy blocks the assistant. Multi-model OpenClaw can already point one session at a different engine.
An OpenClaw LLM Proxy You Can Point At
Treat the gateway as an OpenAI-compatible provider. OpenClaw keeps speaking its normal provider/model-name string. The OpenClaw LLM proxy is just another base URL.
A practical shape, using names you control:
{
"agents": {
"defaults": {
"model": {
"primary": "gateway/fast-chat",
"fallbacks": ["gateway/strong-chat", "ollama/qwen2.5:14b"]
}
}
}
}
gateway/fast-chat is an alias, not a model you buy. Map fast-chat to a small hosted model and strong-chat to a frontier model. Keep a local Ollama tag last, and do not put it first until it passes a tool call.
Point the provider base URL at the proxy. Store the proxy key in provider auth or an env file, not in a file you might commit. After a restart, force a tool call and confirm the alias in the gateway log. If the call hangs, use the timeout notes before you add another provider. The Ollama LLM guide covers that local fallback.
AI Model Router Rules That Actually Save Money
An AI model router saves money only when the rules match the work. A policy that sends everything to the expensive model is a slower way to overpay. Start with three rules and a week of logs.
- Default to the small model. Heartbeats, classification, and short replies stay on
fast-chat. - Escalate on failure or task type. Coding, multi-step research, and any turn that already failed once go to
strong-chat. Retrying the weak model three times is not savings. - Pin private context to local. Personal notes, credentials, and unpublished files stay off the hosted API.
The Cheapest LLM API for OpenClaw
The cheapest LLM API for OpenClaw is usually this split, not one bargain id. Log the alias, the upstream model, token count, and retries. Move a route only when that log shows waste. Do not remap because a new model launched this week.
Compare local and hosted cost on the cheapest LLM page, and see the rest of the bill in OpenClaw cost per month. A morning summary should not use the coding model. Set that in cron config, or let the alias do it.
Open Source LLM Router or a Hosted Gateway
You can run the router or rent one. An open source LLM router such as LiteLLM can sit on the same VPS as OpenClaw. You hold the vendor keys, map aliases, and keep prompts off a third-party log. You also own updates and the log disk. If the proxy shares the OpenClaw server, do not publish its port. Keep it on localhost.
A hosted LLM gateway such as OpenRouter is one key and a catalog. Setup is shorter. You add another company, often a markup, and a privacy policy you should read. That is fine while you compare models. It is a weak fit if you self-host so prompts stay on your hardware. A self-hosted LLM or private LLM loses the point if every prompt is copied elsewhere.
Run it yourself when notes are private. Rent it while you are still comparing models. Either way, OpenClaw should see a stable alias in and a real model out. On a new box, use the self-hosted AI VPS setup before you add the gateway.
When You Should Skip the Gateway
Skip the extra process if all of these are true:
- One person uses the assistant.
- One provider key is enough, plus a local fallback you already configured in OpenClaw.
- The monthly model bill is small enough that a routing bug would cost more time than it saves.
- You do not have a second app that needs the same routes.
Set primary and fallbacks in OpenClaw and move on. An unchecked gateway fails quietly: the assistant looks down, the vendor is fine, and the bug is a proxy you forgot. Add the LLM gateway when a real constraint shows up. Until then, a clear model config beats a router with no rules.
Set a Model Before You Add a Proxy
Install OpenClaw, point primary at a model you trust, and add one fallback. Put a gateway in front only after that default is boring and reliable.
Install OpenClaw Free