You deploy OmniRoute on a remote Linux VPS, verify that curl https://gw.internal.dev/v1/models returns HTTP 200 OK, paste "ANTHROPIC_BASE_URL": "https://gw.internal.dev/v1" into ~/.claude/settings.json, and type your first prompt in Claude Code. The CLI fails immediately with HTTP 404 Not Found on POST /v1/v1/messages. After stripping /v1, routine prompts answer, only for 90-second multi-file refactors to abort mid-turn with truncated tool-call JSON, Nginx 504 Gateway Timeout responses, or container exit code 137 when OmniRoute's default 1024 MB Node heap runs out of memory.
Routing an interactive coding agent through a local or VPS gateway exercises failure modes that short chat completions never touch: long-lived Server-Sent Events (SSE) streams, multi-megabyte AST context payloads, strict Anthropic SDK path concatenation, and stepped per-request token pricing tiers.
Five Proxy, Config, and Heap Bugs That Break OmniRoute + Claude Code
1. Double /v1 HTTP 404s, Startup Env Caching, and Auth Token Precedence
OmniRoute listens on http://localhost:20128 by default and mounts OpenAI- and Anthropic-compatible routes under /v1. However, Anthropic's TypeScript SDK inside Claude Code automatically appends /v1/messages to ANTHROPIC_BASE_URL. Setting ANTHROPIC_BASE_URL to http://localhost:20128/v1 doubles the path into /v1/v1/messages and returns HTTP 404; always set the bare origin http://localhost:20128 (or https://gw.internal.dev on a VPS) with no trailing /v1 or slash. Remember that the claude binary reads the env block of ~/.claude/settings.json only once at process startup, so editing settings.json inside an already-running terminal session has no effect until you exit and relaunch claude.
Watch two authentication traps alongside base URLs. Inside Claude Code, ANTHROPIC_AUTH_TOKEN takes strict precedence over ANTHROPIC_API_KEY; a stale ANTHROPIC_AUTH_TOKEN exported in ~/.zshrc overrides a valid gateway key in settings.json and triggers HTTP 401. On the server side, enabling REQUIRE_API_KEY=true in OmniRoute protects POST /v1/messages, yet intentionally leaves GET /v1/models unauthenticated, meaning a bare /v1/models curl check never proves your bearer token works.
2. Missing anthropic-version Headers and HTTP 400 Ambiguous Model Collisions
Anthropic's Messages API requires anthropic-version: 2023-06-01 on every request; reverse proxies or WAF rules that strip custom headers trigger HTTP 400 invalid_request_error. Inside OmniRoute itself, connecting both a Claude Code OAuth provider (prefix cc/) and a direct Anthropic API key provider (prefix claude/) creates a routing collision whenever Claude Code requests an unprefixed model ID like claude-haiku-5-5 or claude-sonnet-4-5, returning HTTP 400 Ambiguous model. Resolve this either by mapping explicit prefixed model IDs via omniroute setup-claude or by setting OMNIROUTE_PREFER_CLAUDE_CODE_FOR_UNPREFIXED_CLAUDE_MODELS=true in the gateway environment.
3. VPS Reverse-Proxy SSE Buffering, 504 Timeouts, and Truncated Tool JSON
Claude Code streams tool calls as incremental content_block_delta (input_json_delta) SSE frames. Default Nginx upstreams enable proxy_buffering on and enforce proxy_read_timeout 60s. When a model spends 75 seconds reasoning before emitting tokens, Nginx drops the socket with HTTP 504 Gateway Timeout; when Nginx buffers partial 4 KB / 8 KB chunks on slow flushes, connection resets slice input_json_delta payloads mid-object so file edits fail JSON parsing. Disable proxy buffering explicitly in Nginx (or set flush_interval -1 inside Caddy's reverse_proxy block):
location /v1/ {
proxy_pass http://127.0.0.1:20128/v1/;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
add_header X-Accel-Buffering no;
}
4. HTTP 429 / 529 Fallback Chains and 1024 MB Docker V8 Heap OOMs
When upstream providers return HTTP 429 (rate_limit_error) or Anthropic returns HTTP 529 (overloaded_error), OmniRoute combo routes retry against secondary providers automatically—provided the gateway process survives long coding sessions. The official diegosouzapw/omniroute:latest container defaults to a 1024 MB Node V8 heap limit, which hits out-of-memory crashes when translating concurrent 100k-token SSE streams and holding request logs. Launch production coding gateways with an 8 GB V8 heap inside a 10 GB container ceiling:
docker run -d --name omniroute \
-p 127.0.0.1:20128:20128 \
-e REQUIRE_API_KEY=true \
-e OMNIROUTE_MEMORY_MB=8192 \
-e OMNIROUTE_PREFER_CLAUDE_CODE_FOR_UNPREFIXED_CLAUDE_MODELS=true \
--memory=10g \
-v omniroute-data:/app/data \
diegosouzapw/omniroute:latest
5. The 100,000-Input-Token Pricing Cliff on Haiku 5.5
Routing subagents or routine repo edits to claude-haiku-5-5 saves substantial API spend until context drifts past 100,000 input tokens. Under Anthropic's October 2026 pricing schedule, Haiku 5.5 standard requests up to 100,000 input tokens cost $0.10 / $0.50 per million input/output tokens ($0.05 / $0.25 Batch), jumping 5x to $0.50 / $2.50 ($0.25 / $1.25 Batch) on all input and output tokens in any request exceeding 100,000 input tokens. Leaving Claude Code's auto-compaction near its default window lets repository sessions cross 100,001 tokens and multiply per-turn billing fivefold; pinning CLAUDE_CODE_AUTO_COMPACT_WINDOW=85000 triggers context compaction safely below the cliff.
OmniRoute & Claude Code Diagnostic Matrix
| Symptom / HTTP Status | Root Cause Layer | Exact Fix / Header / Env Flag | Verification Command |
|---|---|---|---|
HTTP 404 on POST /v1/v1/messages |
Claude Code SDK path join + startup env cache | Set ANTHROPIC_BASE_URL=http://localhost:20128 (no /v1); restart claude CLI |
curl -i http://localhost:20128/v1/messages -X POST (expect 401/400, never 404) |
HTTP 401 despite valid ANTHROPIC_API_KEY |
Shell env precedence or misleading /v1/models probe |
unset ANTHROPIC_AUTH_TOKEN (wins over API key); remember REQUIRE_API_KEY=true skips /v1/models |
env | grep ^ANTHROPIC_ and authenticated POST /v1/messages check |
HTTP 400 Ambiguous model or missing version |
Dual cc/ + claude/ providers or proxy header strip |
Set OMNIROUTE_PREFER_CLAUDE_CODE_FOR_UNPREFIXED_CLAUDE_MODELS=true; preserve anthropic-version: 2023-06-01 |
curl -sS -H "anthropic-version: 2023-06-01" ... /v1/messages |
HTTP 504 at 60s or truncated tool-call JSON |
VPS reverse proxy SSE chunk buffering | Nginx: proxy_buffering off; proxy_read_timeout 300s; X-Accel-Buffering: no; Caddy: flush_interval -1 |
curl -N -I https://gw.internal.dev/v1/messages (verify X-Accel-Buffering: no) |
Gateway socket reset / Docker exit 137 or 134 |
Default 1024 MB Node V8 heap exhaustion |
Run container with -e OMNIROUTE_MEMORY_MB=8192 --memory=10g |
docker inspect omniroute --format '{{.HostConfig.Memory}}' |
| 5x per-turn API cost jump past 100k context | Haiku 5.5 per-request >100,000 input cliff |
Export CLAUDE_CODE_AUTO_COMPACT_WINDOW=85000 inside ~/.claude/settings.json |
Inspect OmniRoute request log input_tokens <= 90000 across long sessions |
Worked Example: 1,200-Turn Monthly Spend & Session Headroom Math
Consider a worked example for a developer executing 1,200 Claude Code turns per month on claude-haiku-5-5 standard API rates (excluding prompt cache discounts to isolate base-rate exposure), split into 900 routine turns at 45,000 input / 3,500 output tokens and 300 deep-context turns that grow to 120,000 input / 4,000 output tokens when left uncompacted under a 190,000-token window:
- Under the uncompacted configuration, the
900routine turns stay below100,000input tokens ($0.10 / $0.50per 1M):900 × 45,000 = 40.50Minput tokens cost40.50 × $0.10 = $4.05, and900 × 3,500 = 3.15Moutput tokens cost3.15 × $0.50 = $1.575, totaling$5.625($0.00625/turn). The300uncompacted turns cross100,000input tokens and trigger the$0.50 / $2.50cliff on every token:300 × 120,000 = 36.00Minput tokens cost36.00 × $0.50 = $18.00, and300 × 4,000 = 1.20Moutput tokens cost1.20 × $2.50 = $3.00, adding$21.00($0.0700/turn). Monthly spend reaches$5.625 + $21.00 = $26.625(invoiced at$26.63per seat, or$266.25/monthacross a 10-engineer team), with 25% of turns driving78.87%of the bill. - Now set
CLAUDE_CODE_AUTO_COMPACT_WINDOW=85000so those300heavy turns stay compacted at an average of80,000input /4,000output tokens, adding60automatic summary turns (one every five heavy turns at85,000input /2,000output tokens). All1,260requests now price at$0.10 / $0.50: the900routine turns remain$5.625; the300compacted turns drop to24.00M × $0.10 ($2.40) + 1.20M × $0.50 ($0.60) = $3.00; and the60compaction turns add5.10M × $0.10 ($0.51) + 0.12M × $0.50 ($0.06) = $0.57. Total spend falls to$5.625 + $3.00 + $0.57 = $9.195($9.20per seat, or$91.95/monthfor 10 engineers), saving an exact$17.43per developer ($174.30/monthteam-wide, a65.46%reduction). - Compaction also stretches rolling 5-hour subscription windows before OmniRoute spills
429traffic onto paid API keys:25uncompacted heavy turns burn25 × 124,000 = 3,100,000tokens, whereas25compacted turns plus5compactions consume2,100,000 + 435,000 = 2,535,000tokens, preserving565,000tokens (18.2%) of 5-hour quota headroom.
Copy tested settings.json templates and omniroute setup-claude profile commands from the OmniRoute Claude Code setup guide, model custom request mixes in the Haiku 5.5 API pricing calculator, and coordinate 5-hour fallback windows with the usage-limit reset tracker.
Edge Cases and Architectural Boundaries Requiring Manual Checks
Multi-provider failover is not transparent across stateful Anthropic features. Prompt cache entries (cache_read_input_tokens) live inside a single upstream Anthropic organization or cloud region; when OmniRoute fails over mid-session on HTTP 429 or 529 to a secondary API account, Vertex AI, or Bedrock, the new upstream misses the cache completely and bills a cold prompt write or full input count. Similarly, when extended thinking is active, Anthropic attaches a cryptographic signature field to each assistant thinking block and validates it on the next tool-use turn. Failing over mid-conversation to an OpenAI-translated model or stripping unknown block fields invalidates that signature and triggers HTTP 400 invalid_request_error on return to Anthropic. Finally, on corporate networks using TLS-inspecting proxies or internal mTLS CAs, both Node inside OmniRoute and the claude CLI ignore OS trust stores until you export NODE_EXTRA_CA_CERTS=/path/to/corporate-root-ca.pem explicitly.