TL;DR
One line: OpenClaw users change one baseUrl and add one API key to route Claude Sonnet/Opus/Haiku through the CodeGateway aggregation gateway — pay per token.
OpenClaw normalizes provider protocols so a single config drives Qwen / GLM / Gemini / OpenAI / Anthropic. Pointing the Anthropic provider's baseUrl at CodeGateway's Anthropic-compat endpoint removes the dependency on direct upstream Anthropic API access.
This is the minimum viable OpenClaw + CodeGateway integration path. Claude Code, Codex CLI, and Anthropic SDK setups have their own dedicated guides.
1. When this is useful
- You already orchestrate multiple AI agents with OpenClaw and want to add Claude (Sonnet 4.6 / Opus 4.7 / Haiku 4.5)
- Direct Anthropic access is unreliable for billing or network reasons; you want a stable aggregation gateway
- You want a single Dashboard view of token usage and cost for Claude calls
OpenClaw is an open-source AI agent orchestration framework — see the openclaw GitHub repo. CodeGateway is a multi-model aggregation gateway for Claude / GPT / Gemini — see the CodeGateway homepage.
2. Prerequisites
Item | Requirement |
|---|---|
OpenClaw | Any recent version (this guide follows the current |
Node.js | 18 or newer (OpenClaw requirement) |
CodeGateway account | Registered with billing set up; new accounts get $2 free credit |
Network | OpenClaw process can reach |
The $2 starter credit covers roughly 100 mid-complexity Claude Sonnet calls — enough to validate the configuration plus run a few real tasks.
3. Get a CodeGateway API key
- Sign in to the CodeGateway Dashboard
- Open the API Keys page
- Click Create Key and give it a name (an
openclawprefix helps with attribution on the usage page) - Copy the string starting with
sk-cg-. It is shown only once — store it safely.
We recommend creating a dedicated key for OpenClaw. Don't share one key across Claude Code, Codex CLI, and OpenClaw — splitting keys keeps Dashboard usage attribution clean.
4. Configure OpenClaw
OpenClaw's model configuration lives in ~/.openclaw/openclaw.json under models.providers.anthropic.
4.1 Set baseUrl
Point the anthropic provider's baseUrl at CodeGateway:
{
"models": {
"providers": {
"anthropic": {
"baseUrl": "https://api.codegateway.dev",
"api": "anthropic-messages",
"headers": {
"x-api-key": "${CODEGATEWAY_API_KEY}"
},
"models": [
{ "id": "claude-sonnet-4-6", "name": "Claude Sonnet 4.6" },
{ "id": "claude-opus-4-7", "name": "Claude Opus 4.7" },
{ "id": "claude-haiku-4-5", "name": "Claude Haiku 4.5" }
]
}
}
}
}Note: OpenClaw expands ${ENV_VAR} placeholders. Keep the API key in an env var, not inline in the JSON file.4.2 Export the API key
Add this line to your shell config (~/.bashrc or ~/.zshrc):
export CODEGATEWAY_API_KEY="sk-cg-your-key-here"Reload the shell or run source ~/.zshrc, then restart the OpenClaw process so it picks up the new env.
4.3 Pick a primary model
In agents or bindings, set the target agent's model to the anthropic model id:
{
"agents": {
"code-architect": {
"model": { "provider": "anthropic", "id": "claude-sonnet-4-6" }
}
}
}Quick model selection guidance:
Model | When to use | Notes |
|---|---|---|
| Default workhorse | Good price / performance, covers ~80% of orchestration cases |
| Complex architectural reasoning, long-context planning | Higher unit price; reserve for high-leverage decisions |
| High-frequency small tasks, worker agents | About 4x cheaper than Sonnet, lower latency |
5. Verify connectivity
Smallest possible check — let OpenClaw run a one-line greeting:
openclaw run --agent code-architect --prompt "say hi in one sentence"A correct configuration prints a Claude reply.
You can also hit the CodeGateway Anthropic endpoint directly to verify the key:
curl -sS https://api.codegateway.dev/v1/messages \
-H "x-api-key: $CODEGATEWAY_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 64,
"messages": [{"role": "user", "content": "ping"}]
}'A 200 response with a non-empty content field means the key works.
6. Troubleshooting
6.1 401 Unauthorized / invalid_api_key
- Confirm the env var is actually injected into the OpenClaw process (
echo $CODEGATEWAY_API_KEYshould print) - Confirm the key is correct (starts with
sk-cg-, no leading or trailing whitespace) - Confirm the key is still active in the Dashboard (not disabled or expired)
6.2 403 Forbidden / quota errors
- Out of credit — top up via the Dashboard
- Hit a rate limit — default RPM is generous; for high-frequency worker agents, contact support to request a higher tier
6.3 Model ID errors
- CodeGateway uses hyphenated model ids (
claude-sonnet-4-6). Avoid the dated aliases from Anthropic's docs — the hyphenated form is the most reliable choice in OpenClaw config.
6.4 Network timeouts / connection resets
- A direct connection to
api.codegateway.devworks in most environments. If a corporate firewall blocks it, ask IT to allowlist that domain. - During upstream 5xx blips OpenClaw falls back along your
models.fallbackchain. A common pattern isanthropicas primary withzai/qwenas fallbacks — see the OpenClaw fallback docs.
6.5 Where to see usage
- CodeGateway Dashboard → Usage page: token and cost data sliced by key / model / time range. If you created a dedicated OpenClaw key in step 3, you will see the OpenClaw client's real usage isolated.
6.6 Q&A quick reference
Q: My OpenClaw process can't read CODEGATEWAY_API_KEY, but echo $CODEGATEWAY_API_KEY in the shell prints it. What's wrong?
A: Most often the OpenClaw process started before you exported the env var, so it didn't inherit the new value. After source ~/.zshrc you also need to restart the OpenClaw process.
Q: I run Claude Code and OpenClaw side by side. Can I share one CodeGateway key?
A: Technically yes — we recommend separate keys. The Dashboard usage page slices by key, so a shared key blurs which client consumed which tokens, making cost attribution painful later.
Q: Does CodeGateway's prompt cache behave differently than direct Anthropic?
A: It is a transparent passthrough. Cache hits charge at the cache_read rate (about 1/10 of standard input). In our tests with OpenClaw running Sonnet 4.6 plus a long shared system prompt, enabling caching cut per-call cost by 30–60%.
7. Going further
7.1 Coexisting with other providers
OpenClaw supports multiple providers in the same config. A models.fallback chain like ["anthropic", "zai", "qwen"] keeps Claude as primary with GLM / Qwen as automatic fallbacks. See the OpenClaw fallback config examples.
7.2 One agent, one model
Bind models to agents by job type instead of letting a router pick. Use Opus 4.7 or Sonnet 4.6 for architectural and orchestration agents; use Haiku 4.5 for worker and extraction agents. The result is more predictable behavior and lower cost.
7.3 Prompt cache hit rate
Anthropic's prompt caching passes through CodeGateway end-to-end. Cache reads cost about 1/10 of standard input tokens. If your OpenClaw agents share long, stable system prompts, enabling caching typically cuts per-call cost by 30–60%. See the Anthropic prompt caching docs.
Wrap up
At this point your OpenClaw can call Claude reliably, with all calls aggregated into a single CodeGateway Dashboard for billing and observability.
Suggested next steps:
- Set OpenClaw's default
agent.modelto Sonnet 4.6 to validate the primary path - Switch worker agents to Haiku 4.5 to reduce cost
- Set a budget alert in the Dashboard so you get an email when daily or monthly spend hits a threshold
Run into a setup issue or want a scenario added? File it on the feedback page.