How To: Claude Opus 4.6 1 Million Token Context Running On OpenClaw
Step-by-step guide to enabling 1 million token context with Claude Opus 4.6 on a self-hosted OpenClaw gateway. Includes the 10 issues I hit and how to fix each one. I wanted to upgrade my self-hosted AI gateway from Claude Opus 4.5 to Opus 4.6 and unlock the 1 million token context window. It took me an entire day. Ten things broke. The final proof cost me $9.70 in API fees — in thirty minutes. Here's everything that tried to stop me. Skip the war story. Jump to the complete step-by-step setup guide → I run OpenClaw, an open-source AI gateway, on a local workstation. It connects Claude to my WhatsApp, manages context windows, handles tool calls — basically turns an LLM into a persistent assistant that lives on my machine. My environment: Anthropic had just released Opus 4.6 with support for 1 million token context. My gateway was running Opus 4.5 at 200K. Simple upgrade, right? No. The first thing I checked was Hardcoded. Doesn't matter what the model supports — if no override exists, you get 200K. I changed it to Lesson: Always grep for hardcoded constants before assuming config drives behavior. My runtime config at The source code knew about Opus 4.6, but my local config was pinning the old model. Lesson: When debugging model issues, check both source code defaults and runtime config files. They can disagree. OpenClaw uses pi-ai as its model abstraction layer. My Lesson: Stale dependencies are silent killers. Your To prevent Wall 3 from happening again after every Lesson: Automate the thing that just bit you. After OpenClaw's service environment script ( Lesson: Self-hosted software and systemd have a PATH disagreement that will bite you. Check your service environment with Even after all the fixes, my context window still showed 200K. I dug into pi-ai's model catalog: This is intentional. The 1M context window requires a beta header ( I filed issue #1329 upstream. Lesson: Model catalogs report default capabilities, not maximum capabilities. The difference matters. Here's where it got ugly. To send the beta header, I added a custom Wait, what? I'm using OAuth. It was working 5 minutes ago. After deploying Claude Code's agent teams feature (two parallel investigators — one tracing the sync path, one tracing headers), I found the kill chain: Lesson: When you override HTTP headers, you're not adding — you're replacing. If a framework merges headers with last-write-wins, you need to include everything the original had plus your additions. Every time I ran Lesson: Document your build order. Final boss of the OAuth path. After fixing the header merge, I got: This one isn't a bug. It's a billing limitation. I was authenticated via OAuth using Anthropic's Max subscription (flat-rate plan). The 1M context beta is only available with API key billing (pay-per-token, Tier 4). Lesson: "Supports 1M context" means "supports 1M context on certain billing tiers." Read the fine print. I put the API key directly into It crashed. systemd restarted it. It crashed again. And again. Seventeen times. Two mistakes in one line: The config file declares what kind of auth. The credentials file stores the actual secret. Mixing them up doesn't give you a helpful error — it gives you a crash loop. Lesson: Zod validation errors in a systemd service are invisible unless you're watching the journal. And schema field names with underscores vs hyphens will ruin your afternoon. It worked. I pushed the conversation to 210,000 tokens — past the 200K wall that would have stopped me on OAuth. No compaction. No errors. Still coherent. I also proved it via curl — sending a 250K token prompt directly to the API: Then I checked my Anthropic dashboard. $9.70. In about 30 minutes. This is the part most people won't tell you about 1M context: At 210K context on Opus 4.6, every message costs ~$1.05 just for input tokens — because the entire conversation history gets re-sent with each exchange. The cost compounds with every turn. 1M context is real and it works. But you probably don't want it running all day. Use OAuth for daily chat, switch to API key when you genuinely need to ingest an entire codebase, a full book, or months of system logs in a single session. For anyone running an OpenClaw fork on Fedora (or similar) and wanting 1M context, here's the full process end to end. Go to console.anthropic.com/settings/keys and create a new key. You need Tier 4 access for 1M context. Copy the key — it starts with Create or edit Do not put credentials in Add this to your Check You should see Self-hosted AI is real infrastructure. It breaks like infrastructure. Config drift, stale deps, header conflicts, billing quirks — this is ops work. The "1M context" marketing is true but incomplete. Yes, the model supports it. No, your auth method might not. No, you probably can't afford to run it continuously. Debugging is the product. Every wall I hit is a wall someone else will hit. Writing it down is the most useful thing I can do. Agent teams are underrated. Using Claude Code's parallel agent feature to investigate the header merge bug cut my debugging time in half. Two agents, two hypotheses, converging on the answer. The unsexy fix is usually right. After all that work, my daily driver is still OAuth at 200K. The 1M capability is there when I need it — for codebase analysis, ingesting months of logs, or proving a point for $9.70. This is the first real post on bold.casa. I'm building in public — AI tooling, self-hosted infrastructure, and whatever else needs taking apart. Follow along via RSS or Atom.🚀 Just Want the Working Config?
What Broke
The Setup
rpm-ostree based)openclaw/openclaw, running as a systemd user serviceWall 1: The Default Was Hardcoded
src/agents/defaults.ts:;
1_000_000, committed, and opened PR #10536.# Fix: edit src/agents/defaults.ts
Wall 2: Config Override Stuck on the Old Model
~/.openclaw/openclaw.json still had:"agents":
# Fix: update the model in openclaw.json
# Find this line:
# "primary": "anthropic/claude-opus-4-5"
# Change to:
# "primary": "anthropic/claude-opus-4-6"
# Restart the gateway
Wall 3: "Unknown model: anthropic/claude-opus-4-6"
node_modules had pi-ai@0.51.3 — which didn't know Opus 4.6 existed. The package.json specified 0.52.6, but the lockfile hadn't been synced after a recent pull.package.json can say one thing while node_modules runs another.# Fix: sync dependencies and rebuild
# Restart
Wall 4: Stale Deps Prevention (Git Hook)
git pull, I created a post-merge hook:# Fix: create git-hooks/post-merge
# If your git hooks dir is configured:
Wall 5: systemd Can't Find Node
pnpm build, the control UI failed to build inside systemd:env: 'node': No such file or directory
src/daemon/service-env.ts, lines 69/78) assumes ~/.nvm/current/bin exists — that's an fnm convention. I use nvm, which puts node at ~/.nvm/versions/node/v22.22.0/bin/. systemd doesn't source .bashrc, so the nvm PATH setup never runs.systemctl --user show openclaw-gateway.service --property=Environment or just pre-build manually.# Fix: pre-build the UI manually (workaround)
# Verify it's there:
# Restart
Wall 6: The Model Registry Lies (On Purpose)
// node_modules/@mariozechner/pi-ai/dist/models.generated.js
anthropic-beta: context-1m-2025-08-07). Without it, the API hard-rejects anything over 200K. So the model registry reports the safe default, not the maximum.# Fix: override the context window in openclaw.json
# (see "The Config That Works" section at the end for the full config)
# The key field is:
# "contextWindow": 1000000
# inside models.providers.anthropic.models[]
Wall 7: The Header That Ate Authentication
models.providers.anthropic config to openclaw.json with the context-1m-2025-08-07 header. Restarted. Got:401 authentication_error: "OAuth authentication is currently not supported."
models.providers.anthropic triggers ensureOpenClawModelsJson() in src/agents/models-config.tsnormalizeProviders() in src/agents/models-config.providers.ts (line 233-256) sees the provider has models but no apiKey, so it injects the OAuth token as apiKeymergeHeaders() in providers/anthropic.js uses Object.assign() — last write winsanthropic-beta header overwrote the default oneoauth-2025-04-20 — required for OAuth to work# Fix: include ALL required beta features in the custom header
# In your openclaw.json models.providers.anthropic.models[].headers:
#
# "anthropic-beta": "claude-code-20250219,oauth-2025-04-20,context-1m-2025-08-07,fine-grained-tool-streaming-2025-05-14,interleaved-thinking-2025-05-14"
#
# Missing any one of these will break a different feature.
# The critical ones:
# oauth-2025-04-20 → required for OAuth auth
# context-1m-2025-08-07 → required for 1M context
# claude-code-20250219 → required for tool use
Wall 8: Build Nukes the UI
pnpm build, it wiped dist/ — including the pre-built control UI from Wall 5. I got burned by this three times before I learned.pnpm build && pnpm ui:build should probably be a single script.# Fix: always rebuild UI after building
&&
# Or add a script to package.json:
# "build:all": "pnpm build && pnpm ui:build"
Wall 9: "The long context beta is not yet available for this subscription"
400 invalid_request_error: "The long context beta is not yet available for this subscription"
Auth Method Billing Context Limit 1M Support OAuth token ( sk-ant-oat-...)Flat rate (Max plan) 200K ❌ API key ( sk-ant-api03-...)Per token 1M ✅ # Fix: Get an API key from Anthropic
# 1. Go to https://console.anthropic.com/settings/keys
# 2. Create a new API key
# 3. Copy it (starts with sk-ant-api03-)
# 4. You'll need Tier 4 access for 1M context
#
# Don't put it in openclaw.json — see Wall 10.
Wall 10: The Crash Loop
openclaw.json with mode: "api-key" and apiKey: "sk-ant-api03-...". Restarted the gateway.journalctl --user -u openclaw-gateway.service | grep -c "Started"
17
api-key vs api_key: The Zod schema validation expects api_key (underscore). The hyphenated version silently fails validation and crashes the process.openclaw.json. They go in a separate auth-profiles.json file at ~/.openclaw/agents/main/agent/auth-profiles.json, with type: "api_key" and key: "...".# Fix: put the API key in the CORRECT file with the CORRECT field names
# 1. Edit the auth profiles file (NOT openclaw.json):
# 2. Restart:
# 3. Verify it's running (not crash-looping):
# If something's wrong, check the journal:
The Proof
📚 Context: 210k/1.0m (21%) · 🧹 Compactions: 0
# This succeeds with the beta header:
# → 200 OK
# This fails WITHOUT the beta header:
# → 400: "prompt is too long: 250033 tokens > 200000 maximum"
The Economics
Metric OAuth (Flat Rate) API Key (Per Token) Context limit 200K 1M Monthly cost Fixed (Max plan) Variable Cost at 100K context $0 ~$0.50/message in Cost at 500K context N/A ~$2.50/message in Cost at 1M context N/A ~$5.00/message in The Complete Config That Works
Step 1: Get an Anthropic API Key
sk-ant-api03-.Step 2: Store the Key
~/.openclaw/agents/main/agent/auth-profiles.json:
openclaw.json. That file is for config, not secrets.Step 3: Add the Model Config
~/.openclaw/openclaw.json:
Step 4: Rebuild and Restart
Step 5: Verify
/status in your chat or look at the logs:
Context: Xk/1.0m in your status output.What I Learned