Blog

LLM proxy vs LLM gateway for Claude Code and Codex

An AI gateway is one endpoint in front of model providers that handles routing, keys, budgets, rate limits and logs. It forwards each request as it is, so the request costs the same. Coding agent cost comes from huge, repeated context, so a smaller bill also needs something that shrinks the request.

67.7%
of agent spend is re-sent context
13.2%
is output
72%
under baseline on a real session through condense

What an AI gateway does

One endpoint replaces a handful of provider keys. LiteLLM is the best-known open-source option; managed gateways offer the same without a server.

  1. 1
    Routing

    One API over several providers, with fallbacks and load balancing.

  2. 2
    Key management

    Provider keys stay on the server. Revoke one person without rotating all.

  3. 3
    Metering and budgets

    Spend per key, user, team or project, with limits and alerts.

  4. 4
    Rate limits and policy

    Which models a team may use, how fast, sometimes redaction.

  5. 5
    Logging

    Request records for debugging, audit and cost reports.

Proxy vs gateway

Every gateway is a proxy, not the reverse. A gateway saves money by saying no; it never makes an allowed request smaller.

NeedRouting gatewayCompression proxy
One endpoint for many providersYesUsually limited to supported routes
Central provider keysYesVaries
Spend per person or teamYesOften, since it sees every request
Budgets and capsYesVaries
Smaller requestsNo, forwards as isYes, rewrites context
Lower cost per taskOnly by blocking or reroutingYes, fewer tokens per turn

Why agents need more

Agents re-send their whole context every turn, so requests never repeat and gateway caching misses. Provider prompt caching discounts those tokens but still bills them, and expires after about five idle minutes.

How agents connect

Both kinds plug in the same way: change the base URL. Check what a third party stores first, using our proxy safety checklist.

AgentWhere to set itNotes
Claude CodeANTHROPIC_BASE_URLMessages format; gateway key in ANTHROPIC_AUTH_TOKEN. Also Bedrock and Vertex direct.
Codex~/.codex/config.tomlCustom model provider with base URL and wire API
OpenCodeopencode.jsonPer-provider base URL and headers

What a coding team needs

Gateways are easy to over-buy. The two can stack, but every hop adds latency and another vendor that sees your code.

You areFirst painWhat fits
Solo on a subscriptionPlan runs outNo gateway; shrink the context
Small team on API keysWho spent whatPer-developer keys or telemetry, then budgets
Many apps, many vendorsKeys, audit, fallbacksRouting gateway such as LiteLLM
Agent bill is the problemCost per taskCompression proxy such as condense

Where condense fits

condense compresses earlier turns of long conversations and leaves code, patches and errors untouched. Short conversations pass through uncompressed.

One real session, priced
Opus, baseline vs through condense
Baseline
$771
condense
$214
The bill came in 72% under baseline. From the anatomy of a token bill.

Frequently asked questions

What is the difference between an LLM proxy and an LLM gateway?

Both sit on the request path. A gateway is a control plane for routing, keys, budgets and logs; a proxy is anything in the path, including tools that change the request.

Can I use LiteLLM with Claude Code?

Yes. Set ANTHROPIC_BASE_URL to the LiteLLM proxy and give Claude Code a LiteLLM key. Anthropic's LLM gateway docs cover the setup.

Does an AI gateway reduce token costs?

Only indirectly, through budgets and routing. Agent turns are almost never identical, so gateway response caching rarely hits.

Do I need a gateway for a single developer?

Usually not. A gateway pays off when several people share provider keys and need per-team limits.

Is it safe to route coding agents through a proxy?

It can be. Check storage, retention, training use and where requests are processed before sending code through it.

All posts