Solutions
Partner Offerings
Insights
For Talent
About
Login

The AI gateway caching trap: Why multi-model bills stay high

AI gateway bills often stay high because result caching is opt-in and only the provider's prompt cache runs by default. Cutting costs takes cache-aware routing and spend attribution.

Kayode Ojo
Software Engineer
Published:
Aug 26, 2026
Updated:
Aug 26, 2026
10 min
The AI gateway caching trap: Why multi-model bills stay high
Key takeaways
  1. OpenRouter and Portkey offer result caching, which skips the model call, only as an opt-in; left off, the only cache at work is the provider's prompt cache, which just discounts reused input tokens.
  2. Switching a conversation to a cheaper model mid-stream discards the warm cache and can cost more than it saves.
  3. A gateway centralizes one API for all models, key management, retries and failover, and token tracking by team, app and model.
  4. Gateways add a network hop, a single point of failure and supply chain risk: LiteLLM suffered an attack in March 2026 that harvested API keys.
  5. You need a gateway once you add a second provider or service, get a surprise invoice or need per-feature spend attribution.

Teams running multiple models in production often make the same mistake: they wire up an AI gateway like OpenRouter or Portkey, tick the “caching” box, and assume their bill will drop. Weeks later, the invoice remains unchanged, and no one understands why.

The problem stems from the definition of caching. Gateways typically offer one of two cache types. A result cache stores a full prompt and completion pair, skipping the model call entirely on a repeat request and saving 100% of the cost. A prompt cache is native to vendors like Anthropic and OpenAI; it only discounts reused input tokens (typically by 50% to 90%) while still executing the model run.

Services like OpenRouter and Portkey do offer result caching, but only when you switch it on: OpenRouter's response caching needs the X-OpenRouter-Cache header or a preset, and Portkey's simple and semantic cache has to be added to the gateway config. Leave it off and the only cache working for you is the provider's prompt cache. On a workload processing 10 million requests a month, relying only on prompt caching might cut your spend by 39% instead of the 54% a result cache could achieve. If your “cached” AI features are still expensive, this is likely the culprit.

This highlights a broader truth about AI gateways: the term obscures critical implementation details. The gap between “has caching” and “has caching that actually saves money” mirrors the gaps found in routing, fallback logic, and budget enforcement.

What an AI gateway actually does

Strip away the vendor marketing, and an AI gateway is essentially a proxy. Instead of calling OpenAI, Anthropic, or Google Gemini directly, your application calls the gateway. The gateway holds the provider keys, routes or rewrites the destination, and returns a consistently formatted response regardless of which model executed the request.

This architectural pattern is not new. A decade ago, Kong, Apigee, and other API gateways solved the same problem for REST APIs: developers repeatedly copied authentication, rate limiting, and logging logic into every service until the industry centralized it into a single layer. Point that layer at large language models (LLMs) instead of API endpoints, and you have an AI gateway.

When engineered correctly, this layer adds negligible latency. Bifrost, an open-source AI gateway built in Go, claims just 11 microseconds of added latency per request at 5,000 requests per second. You are not adding a delay; you are adding a checkpoint.

You will often hear the term “LLM gateway” used interchangeably. Technically, an LLM gateway focuses on developer-facing routing and tooling, while an AI gateway emphasizes enterprise governance and handles multimodal traffic (image, audio, and agent workflows). In practice, the industry uses both terms for the same concept.

Five core gateway functions

A deployed gateway performs five distinct jobs:

  • Provides a unified interface: Every provider has unique request formats and quirks. The gateway abstracts this behind a single schema—typically the OpenAI format, which the industry largely adopted. Swapping models becomes a configuration change instead of a code rewrite.
  • Centralizes key management: Instead of scattering provider keys across every AI-integrated service, the gateway stores them securely. Applications use disposable virtual keys, which the gateway exchanges for real credentials. If a key is compromised, you revoke the virtual key without breaking downstream services.
  • Automates retries and failovers: When a provider throws an error or hits a rate limit, the gateway automatically retries the request or routes it to a backup model before the user experiences a failure.
  • Tracks token usage: The gateway logs every input and output token, tagging them by team, application, and model. This telemetry reveals exactly which features drive your bill in real time.
  • Consolidates observability: Because all requests flow through a single point, the gateway acts as the centralized dashboard for monitoring latency, error rates, and spend, eliminating the need to cross-reference multiple provider portals.

The routing debate: Rules vs. smart routing

Routing receives the most attention—and the most marketing hype—in the gateway ecosystem. The premise is straightforward: not every request requires your most expensive model.

The industry splits routing into two approaches. The first is rule-based routing. Engineering teams define explicit logic: route well-defined tasks to cheaper models, isolate specific customer traffic to dedicated deployments, and fall back to backups during outages. It is highly predictable, and when a failure occurs, the debugging path is obvious.

The second approach is heavily marketed as smart routing. Here, the gateway dynamically evaluates prompt complexity and selects the most appropriate model. Research supports this capability. The RouteLLM project, developed by UC Berkeley and Anyscale, demonstrated that a router could maintain 95% of GPT-4's response quality while sending only ~25% of requests to GPT-4 itself. The remaining requests routed to Mixtral 8x7B, drastically reducing costs. 

Crucially, the routing performance held even when researchers swapped the underlying model pairs without retraining.

However, there is a fundamental catch. For a router to reliably determine that a prompt exceeds a smaller model's capabilities, it must understand the prompt almost as well as the expensive model. If the router possessed that level of comprehension, the expensive model would be redundant. Smart routing remains genuinely useful—most real-world traffic is simple enough for a lightweight classification check—but it is not the frictionless magic bullet that vendor marketing suggests.

The cache invalidation trap

Cache invalidation quietly burns engineering budgets. Production AI architectures rely heavily on prompt caching. During extended model interactions, large segments of the conversation remain “warm” on the provider's infrastructure. Reusing these cached tokens instead of reprocessing the entire context window keeps costs manageable.

Consider a smart router that decides to switch a mid-conversation request to a cheaper model to save a few fractions of a cent. That newly selected model has no warm cache. It must ingest the entire conversation history cold. The cost of that context reload easily eclipses the savings generated by the lower per-token price. You optimized the unit economics but inadvertently multiplied the total token count.

To fix this, the router must evaluate the cache state before executing a switch. Once a model's cache is warm, the threshold for routing away from it must increase significantly. The projected savings must outweigh the cost of a cold start. Naive routing setups completely miss this nuance.

Semantic caching introduces a different vector of risk. A standard exact-match cache only reuses an answer if the new prompt is character-for-character identical to a previous one. Semantic caching matches on intent, converting prompts into vector embeddings to identify near-duplicates. When implemented correctly, it intercepts redundant traffic and serves responses instantly. However, if the similarity threshold is too permissive, it matches queries that look structurally identical but demand opposite outcomes. For example, “sort ascending” and “sort descending” exist extremely close to one another in vector space. If the gateway cannot differentiate them, it serves the wrong answer with absolute confidence.

The operational costs of a gateway

Gateways introduce operational trade-offs. Architecturally, they add a network hop. Every request detours through the proxy before hitting the LLM provider. While this overhead is generally negligible compared to the multi-second latency of model inference, engineering teams building latency-sensitive applications must measure the impact directly rather than trusting vendor benchmarks.

The primary architectural cost: it intentionally creates a single point of failure. Because every request routes through this layer, a gateway outage breaks every downstream AI feature. Teams must engineer bypass paths that let applications reach providers directly during an incident, and back those paths with rigorous monitoring of the gateway infrastructure.

Gateways also carry a massive trust cost. Because this layer centralizes all provider credentials, it becomes the most high-value target in your stack. In March 2026, LiteLLM—a widely adopted open-source gateway—suffered a severe supply chain attack. Attackers compromised a CI dependency, published backdoored PyPI releases, and systematically harvested API keys, cloud secrets, and credentials from infected environments. This incident is not an argument against self-hosting. It is a mandate to pin container image versions, verify signed releases, and secure the gateway layer with the same rigor applied to production databases.

Comparing your gateway options

LiteLLM and Cloudflare represent the most common starting points, but the optimal choice depends entirely on deployment constraints and operational maturity.

__wf_reserved_inherit

If you are evaluating Portkey, note that Palo Alto Networks completed its acquisition of the company on May 29, 2026, and made it the core AI gateway of its Prisma AIRS security platform. While Palo Alto Networks pledged to support existing customers, embedding a long-term architectural dependency on a product now governed by a massive security vendor’s roadmap requires careful risk assessment.

For engineers building AI systems for external clients, LiteLLM is generally the safer recommendation. 

Clients rarely want a new recurring SaaS expense stacked on top of their inference costs. They need hand-offs their internal teams can maintain without inheriting forced vendor relationships. LiteLLM is free, self-hosted, scalable, and supports the exact mix of providers most client projects demand. The trade-off—owning the infrastructure—is standard practice for competent engineering teams. Portkey remains a viable alternative if the client demands managed observability without touching infrastructure, as its lower tiers accommodate smaller budgets.

Deployment paths

Deployment strategies generally branch into two paths.

If you require full infrastructure control, LiteLLM is the default starting point. Deployment involves a configuration file mapping model names to provider credentials, a Docker container and, for virtual keys and spend tracking, a PostgreSQL database. Developers simply point their existing OpenAI SDK client at the LiteLLM endpoint, requiring zero downstream codebase changes. Fallback rules run directly from the configuration file, while virtual keys, with their per-key budgets and rate limits, need the PostgreSQL database and a master key. The cost is operational burden: your team is responsible for patching, monitoring, and securing the deployment.

If you want to avoid managing infrastructure, Cloudflare AI Gateway offers a fully managed alternative. Developers provision the gateway via a dashboard and update their application's base URL to point to Cloudflare’s edge network, which handles caching, rate limiting, retries, and logging. Cloudflare's Unified Billing, first released in closed beta in August 2025, allows teams to pay for multi-provider usage on a single Cloudflare bill, with a 5% fee on the credits they buy. However, this locks you into Cloudflare's ecosystem; if compliance mandates require in-VPC or air-gapped deployments, this managed route is impossible.

When you actually need a gateway

If you are calling a single provider from a single monolithic application, skip the gateway and call the model directly. A gateway only earns its place the moment your architecture becomes plural: integrating a second provider, spinning up a second microservice, absorbing your first surprise invoice, or trying to attribute cloud spend to a specific feature. The “one API key for many models” pitch is the least interesting value proposition. AI gateways exist because model inference has evolved from a siloed application feature into shared, distributed infrastructure.

Taking control of the AI blast radius

An AI gateway transforms unpredictable LLM spend and unmanaged blast radii from reactive crises into governed processes. Whether you self-host LiteLLM, offload to Cloudflare, or deploy a vendor solution, the test is simple: Can you state exactly which feature drove your AI spend last month? Do you know exactly what happens to your application if OpenAI or Anthropic experiences an outage right now?

If answering either question requires piecing together data from five different dashboards, you already need an AI gateway. You just haven’t built it yet.

FAQs

What is an AI gateway?

An AI gateway is a proxy between your application and model providers such as OpenAI, Anthropic and Google Gemini. It offers one interface for all models, central key management, automatic retries and failover, and token tracking by team, application and model, much as API gateways did for REST APIs.

Why doesn't AI gateway caching lower my bill?

Often because result caching, which skips the model call entirely, is switched off. OpenRouter and Portkey offer it only as an opt-in, so by default the only cache at work is the provider's prompt cache, which discounts reused input tokens but still runs the model. Routing a conversation to a cheaper model mid-stream also throws away the warm cache and forces a full reload of the history, which can cost more than the cheaper tokens save.

Should you use smart routing between AI models?

Carefully. RouteLLM kept 95% of GPT-4's response quality while sending about 25% of requests to GPT-4, but a router must understand a prompt almost as well as the expensive model. Routers should also check cache state and demand larger projected savings before moving away from a warm model.

When do you need an AI gateway?

Not for a single provider in one monolithic application. A gateway earns its place when you add a second provider or microservice, receive a surprise invoice or need to attribute AI spend to features. A quick test: can you say which feature drove last month's AI spend?

What are the risks of running an AI gateway?

It adds a network hop, so measure latency yourself, and it becomes a single point of failure that needs bypass paths and monitoring. It is also a security target: LiteLLM suffered a supply chain attack in March 2026 that harvested API keys, so pin versions and verify signed releases.

Kayode Ojo
Software Engineer
Software engineer with 13+ years of experience across the full stack and 4+ years in generative AI.
More about author

Recent articles