Route Claude Code through a local LiteLLM proxy
Point Claude Code at LiteLLM with ANTHROPIC_BASE_URL, pin a patched release, and keep the proxy private.
Published here · 13 sources · Resume reading
Point Claude Code at a local LiteLLM proxy with ANTHROPIC_BASE_URL set to the proxy root and a credential var the gateway expects [2] [5]. Define Anthropic models in config.yaml, start litellm --config, and unset a conflicting shell ANTHROPIC_API_KEY when a virtual key should win [2]. Pin a current patched PyPI or Docker release before you expose the proxy to anything beyond localhost [7] [8] [9] [11].
Related field note: LiteLLM compromised release response. This page is the routing setup, not a private multi-account failover recipe.
Pin a current patched litellm first
As of 2026-11-20, PyPI reported litellm version 1.110.2 [11]. Run that line or newer after you re-check PyPI and the advisory list on install day.
Two separate security stories matter for this post:
- CISA KEV CVE-2026-40217 (GHSA-wxxx-gvqv-xp7p): unprotected alternate channel / sandbox escape via custom-code guardrail testing. GitHub advisory lists a first patched version at
1.83.10(description also mentions1.83.11/ RestrictedPython). CISA added the CVE to the Known Exploited Vulnerabilities Catalog on 2026-11-18 [8] [9]. Upgrade to1.83.10or later at minimum; prefer current stable. - GHSA-3cv6-jpf6-8222 (CVE-2026-84377): authenticated SSRF and provider-credential exfiltration via unvalidated request-body routing parameters, with patched lines starting at examples such as
1.88.6/1.96.2and later backports listed in the advisory [7].
March 2026 PyPI supply-chain compromise of 1.82.7 / 1.82.8 is a third story already covered on the field note and LiteLLM's own security blog [10] [12] [13]. Those builds were removed from PyPI; still pin and verify.
Warning: keep a local proxy off the public internet when you can. Admin credentials on a reachable proxy raise the blast radius of every authenticated bug class above.
Write a minimal config.yaml
LiteLLM documents top-level sections model_list, router_settings, litellm_settings, general_settings, and optional environment_variables [1]. Shape from the Claude Code client docs [2]:
model_list:
- model_name: claude-sonnet-5
litellm_params:
model: anthropic/claude-sonnet-5
api_key: os.environ/ANTHROPIC_API_KEY
general_settings:
master_key: os.environ/LITELLM_MASTER_KEYmodel_name is what the client asks for. litellm_params.model is what LiteLLM sends to completion(). Secrets of the form os.environ/NAME read that environment variable [1].
Start the proxy
export ANTHROPIC_API_KEY="YOUR_PROVIDER_KEY"
export LITELLM_MASTER_KEY="YOUR_LOCAL_MASTER_KEY"
litellm --config /path/to/config.yamlDocs examples commonly listen on port 4000 [2]. You should see the proxy process start. Follow the official docs and verify the listen address on your own machine.
Point Claude Code at the proxy
Anthropic and LiteLLM agree on the gateway pattern [2] [4] [5]:
export ANTHROPIC_BASE_URL="http://localhost:4000"
export ANTHROPIC_AUTH_TOKEN="$LITELLM_MASTER_KEY"
export ANTHROPIC_MODEL="claude-sonnet-5"
unset ANTHROPIC_API_KEY
claudeClaude Code appends /v1/messages to the base URL [2] [5]. Use ANTHROPIC_AUTH_TOKEN for Bearer auth or ANTHROPIC_API_KEY for x-api-key, matching what your gateway expects [5]. If both are set, LiteLLM docs say to unset the shell ANTHROPIC_API_KEY so a virtual key in ANTHROPIC_AUTH_TOKEN wins [2].
You should confirm the Anthropic base URL line via Claude Code /status per Anthropic's gateway docs [5]. Optional: CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1 so /model can load gateway entries from GET /v1/models [2] [4]. As of Claude Code v2.1.196, Remote Control is disabled when ANTHROPIC_BASE_URL is not api.anthropic.com [4].
Use documented deployment failover only
Public load-balancing docs: multiple model_list rows can share one model_name; litellm_params.order sets priority; router_settings can set retries and fallbacks [3]. That is reliability for owned keys and deployments, not a measured recipe to rotate personal Claude.ai seats. Save any "beats rate limits" claim for a Part 2 with your own numbers.
Corporate HTTPS_PROXY / HTTP_PROXY / NO_PROXY remain a different layer from ANTHROPIC_BASE_URL [6].
You now have a local gateway shape, Claude Code env wiring, and a patch habit tied to GHSA-3cv6-jpf6-8222 plus CISA KEV CVE-2026-40217.
Send this to the friend who wants Claude Code to go through their own LiteLLM proxy.

Keep this guide
Filed under Claude Code, Security
Questions about this guide
Which env vars point Claude Code at LiteLLM?
Set ANTHROPIC_BASE_URL to the proxy root (for example http://localhost:4000) and authenticate with ANTHROPIC_AUTH_TOKEN (Bearer) or ANTHROPIC_API_KEY (x-api-key) per what the gateway expects. Claude Code appends /v1/messages.
Which litellm version should I run?
A current patched release. As of 2026-11-20 PyPI reported litellm 1.110.2. CISA KEV lists CVE-2026-40217 with a fix line at 1.83.10+. Also read GHSA-3cv6-jpf6-8222 and later advisories before you assume a tag is clean.
Does this post teach multi-account Claude.ai failover?
No. Public LiteLLM docs cover deployment order and fallbacks for owned keys and deployments. Measured multi-seat failover belongs in a later Part 2 with numbers.
Is ANTHROPIC_BASE_URL the same as HTTPS_PROXY?
No. ANTHROPIC_BASE_URL points Claude Code at an LLM gateway. HTTPS_PROXY / HTTP_PROXY / NO_PROXY are the corporate HTTP proxy layer documented separately.
Sources
- LiteLLM: Proxy config.yaml, accessed 2026-11-20docs.litellm.ai
- LiteLLM: Claude Code client setup, accessed 2026-11-20docs.litellm.ai
- LiteLLM: Load balancing, accessed 2026-11-20docs.litellm.ai
- Anthropic: LLM gateway connect, accessed 2026-11-20code.claude.com
- Anthropic: Network configuration, accessed 2026-11-20code.claude.com
- Simon Willison: Malicious litellm_init.pth note, related readingsimonwillison.net
- Full Byte Developer: LiteLLM compromised release responsefullbytedeveloper.com