Skip to Content
Gateways

Gateways

LLM gateways sit between your application and model providers. They expose one baseURL, route across providers, and meter spend — the layer you optimize when Cline, Aider, OpenCode, or a production agent shares one API key.

These guides apply the practice sequence at the gateway layer. Gateways do not replace context hygiene in your editor — they forward what clients send.

When to optimize here

SignalGateway fix
Bill spike with no IDE dashboardActivity / spend logs on the gateway
One API key across dev + CI + prodPer-key caps and workspace budgets
Always billed for frontier modelHaiku-first routing and fallbacks
cached_tokens always zeroStabilize prefix; enable response caching
Double proxy (gateway + gateway)Pick one routing layer

Pair every gateway guide with your IDE guide — trim MCP, rules, and context upstream.

Walk sequence

Every gateway guide follows the same six steps:

  1. Measure — dashboard, exports, or spend API
  2. Cap — per-key limits, workspace budgets, rate limits
  3. Route cheap — fallback chains, price sorting, model allowlists
  4. Cache — prefix caching, response caching, edge cache
  5. Trim upstream — IDE context, MCP, rules
  6. Guardrail in prod — org caps, batch workloads, observability

Gateway comparison

GatewayBillingSelf-hostCachingCapsBest fit
OpenRouterCredits + platform feeNoPrefix + responsePer-key, workspaceBYOK across 500+ models, coding agents
LiteLLMYour provider billsYes (proxy)Provider-dependentVirtual keys, budgetsTeam proxy over local + cloud backends
Vercel AI GatewayProvider rates, no markupNoProvider-dependentVercel dashboardNext.js / AI SDK production apps
PortkeyProvider rates + platformNoGateway cacheBudgets, configsEnterprise fallback chains + observability
HeliconeCredits or BYOK, 0% markupNoPrompt cache proxyRate limitsRequest logging + throttle before provider
Cloudflare AI GatewayProvider ratesNoEdge cacheRate limitsEdge caching, unified analytics

Not here: LocalAI is an inference gateway over local engines — see Self-hosting.

Guides

GatewayGuideDominant waste
OpenRouterTokenminning with OpenRouterFrontier defaults, missing fallbacks, unstable prefixes
LiteLLMTokenminning with LiteLLMUnscoped virtual keys, no spend tracking DB
Vercel AI GatewayTokenminning with Vercel AI GatewayFrontier defaults in AI SDK, no spend monitoring
PortkeyTokenminning with PortkeyMissing budget configs, unbounded fallback chains
HeliconeTokenminning with HeliconeNo rate limits, unlogged agent loops
Cloudflare AI GatewayTokenminning with Cloudflare AI GatewayCache misses, no rate limits at edge

Anti-patterns (all gateways)

Anti-patternWhy it fails
Gateway + gateway stackLatency and fees compound
One key for CI and devOvernight agent loops drain pool
Frontier default on every call60–90% savings left on table from routing
No spend exportCannot attribute by feature or team
Last updated on