Coding Gateways & Model Routing Verified Practitioner Reference

Debugging OmniRoute and Claude Code Gateway Failures: ANTHROPIC_BASE_URL, VPS SSE Buffering, and the 100k Token Cliff

Fix double-/v1 HTTP 404s, ANTHROPIC_AUTH_TOKEN overrides, 400 Ambiguous model collisions, Nginx SSE tool-call truncation, 1024 MB V8 heap crashes, and 5x >100k Haiku 5.5 billing spikes.

Published 2026-11-29 7 min read 1510 words

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 900 routine turns stay below 100,000 input tokens ($0.10 / $0.50 per 1M): 900 × 45,000 = 40.50M input tokens cost 40.50 × $0.10 = $4.05, and 900 × 3,500 = 3.15M output tokens cost 3.15 × $0.50 = $1.575, totaling $5.625 ($0.00625/turn). The 300 uncompacted turns cross 100,000 input tokens and trigger the $0.50 / $2.50 cliff on every token: 300 × 120,000 = 36.00M input tokens cost 36.00 × $0.50 = $18.00, and 300 × 4,000 = 1.20M output tokens cost 1.20 × $2.50 = $3.00, adding $21.00 ($0.0700/turn). Monthly spend reaches $5.625 + $21.00 = $26.625 (invoiced at $26.63 per seat, or $266.25/month across a 10-engineer team), with 25% of turns driving 78.87% of the bill.
  • Now set CLAUDE_CODE_AUTO_COMPACT_WINDOW=85000 so those 300 heavy turns stay compacted at an average of 80,000 input / 4,000 output tokens, adding 60 automatic summary turns (one every five heavy turns at 85,000 input / 2,000 output tokens). All 1,260 requests now price at $0.10 / $0.50: the 900 routine turns remain $5.625; the 300 compacted turns drop to 24.00M × $0.10 ($2.40) + 1.20M × $0.50 ($0.60) = $3.00; and the 60 compaction turns add 5.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.20 per seat, or $91.95/month for 10 engineers), saving an exact $17.43 per developer ($174.30/month team-wide, a 65.46% reduction).
  • Compaction also stretches rolling 5-hour subscription windows before OmniRoute spills 429 traffic onto paid API keys: 25 uncompacted heavy turns burn 25 × 124,000 = 3,100,000 tokens, whereas 25 compacted turns plus 5 compactions consume 2,100,000 + 435,000 = 2,535,000 tokens, preserving 565,000 tokens (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.

Frequently Asked Technical Questions

Why does Claude Code keep hitting /v1/v1/messages after I fix ANTHROPIC_BASE_URL in settings.json?

Claude Code loads ~/.claude/settings.json environment keys once when the CLI process starts and also inherits any variables exported in your parent shell. Exit the active claude session completely, run env | grep ANTHROPIC_BASE_URL in your terminal to confirm your shell profile is not exporting a trailing /v1 URL, and launch a fresh claude process.

Does REQUIRE_API_KEY=true in OmniRoute block public access to GET /v1/models?

No. OmniRoute's REQUIRE_API_KEY=true setting enforces bearer or x-api-key authentication on inference endpoints like POST /v1/messages and POST /v1/chat/completions, while leaving GET /v1/models open for client discovery. On a public VPS, bind Docker to 127.0.0.1:20128 and restrict or authenticate /v1/models inside Nginx, Caddy, or a WireGuard/Tailscale tunnel.

How does Anthropic calculate Haiku 5.5 billing at 100,001 input tokens?

The 100,000-token threshold is evaluated per individual API request against input token count, and crossing it re-prices every input and output token in that request rather than only the excess tokens above 100,000. At standard rates, 100,000 input plus 10,000 output tokens costs $0.015 ($0.10/$0.50 tier), whereas 100,001 input plus 10,000 output tokens jumps to $0.0750005 ($0.50/$2.50 tier).

Why does mid-session provider failover throw HTTP 400 on assistant thinking blocks?

Anthropic signs each extended thinking block with an opaque cryptographic signature and verifies that exact block and signature when conversation history is sent back on subsequent tool-loop turns. If OmniRoute routes one turn through a non-Anthropic provider or strips thinking signatures during format translation, the next turn routed back to Anthropic's /v1/messages endpoint fails signature verification with HTTP 400; start a fresh session (/clear) when switching model families.