What an AI gateway actually does — and when you need one

2026-11-23 · 5 min read · Architecture

A normal API gateway fronts your own services. An AI gateway fronts someone else's services — OpenAI, Anthropic, Google, DeepSeek, Zhipu, and whoever else is serving weights this quarter — and it does that with a request shape that is nearly identical across all of them.

That near-identity is what makes the category possible, and it is also why most "AI gateway" pages describe a feature list rather than a design decision. Here is the decision.

Definition

An AI gateway is a proxy that accepts model-inference requests in one schema, resolves each request to a specific provider and model deployment, enforces policy, records cost and usage, and returns a response the caller can treat as if it came directly from the provider.

Three properties distinguish it from a generic API gateway:

  1. It is model-aware — it understands model, messages, tools, stream, and token accounting.
  2. It is provider-multiplexing — one endpoint, many upstreams, chosen per request.
  3. It is billing-aware — it knows the price of the thing it just served, because providers price differently per model and per direction.
  4. 
    # the entire integration, for any OpenAI-compatible gateway
    from openai import OpenAI
    client = OpenAI(base_url="https://api.cisoma.com/v1", api_key="sk-...")
    

    The five jobs

    1. Schema normalization

    Providers converged on the OpenAI chat-completions shape for compatibility, but not on everything around it: tool-call formats, streaming chunk framing, finish reasons, and error bodies all differ. A gateway flattens those differences so your retry logic has one contract.

    2. Routing

    Per request, the gateway picks a deployment. Three common policies:

    • Cheapest healthy offer — best for batch and background work, where latency is elastic.
    • Cheapest above a latency floor — the practical default for user-facing traffic.
    • Capability or compliance match — route to a provider that supports the tool schema, context length, or data-residency rule you require.

    Learning-based routers exist too and can beat static rules on cost/quality trade-off, but they add a failure mode: the router becomes a model you also have to monitor. See RouteLLM for the research shape.

    3. Failover

    The two failure classes that matter:

    • Hard failures — connection refused, 5xx, provider quota exhausted. Easy: retry elsewhere.
    • Soft failures — first-byte arrives, then the stream stalls. Hard: a naive health check passes right up until your user is staring at a hung response.

    Correct failover draws the retry boundary at the first streamed token. Before it, switch providers freely. After it, you either finish the stream or you surface an error — retrying a partially streamed completion means two billable generations and one confused user.

    4. Cost accounting

    Every request produces a record: model, provider, input tokens, output tokens, effective unit price, latency. That record is the only way to answer questions like "which feature costs more than it earns" or "did a provider quietly swap a cheaper model into my claude-opus-5 calls".

    This is also where gateways differ commercially. Some mark up list price. Some take the best live offer from competing suppliers — the same model can sit at very different points:

    ModelMarket rate / 1M inputOfficial listGap
    claude-opus-5$0.50$5.0090%
    gpt-5.6-terra$0.24$2.0088%
    glm-5.3-flash$0.01$0.1593%
    deepseek-flash$0.0056$0.1496%

    5. Governance

    Key issuance and revocation, per-team budgets, rate limits, prompt logging policy, and — increasingly — the rule for what leaves your network. A gateway is where those become enforceable rather than aspirational.

    When you do not need one

    Be honest about the inverse case:

    • One provider, one model, steady volume. A direct contract is cheaper and has one less hop.
    • No multi-provider intent. Routing value comes from competition between providers for the same model. With one supplier, a gateway is just a proxy with a fee.
    • Hard data-isolation requirements with no self-host option. Self-host instead, or go direct.

    When you do

    Three signals, in the order teams usually hit them:

    1. The second provider appears. Someone asks for a Claude model next to your GPT traffic. Now you have two SDKs, two bills, two rate-limit regimes.
    2. An outage becomes a customer conversation. You want the failover to be a policy, not a hotfix written at 2am.
    3. Cost attribution is requested by finance. "What did the summariser cost in March" is impossible without per-request records.
    4. Build, buy, or both

      Self-hosted (LiteLLM, Envoy-based)Managed gateway
      Time to first requesthours to daysminutes
      Routing intelligenceyour configvendor's live offers
      Price freshnessyour deploy cadenceper request
      Ops burdenyoursvendor's
      Prompt visibilityonly yourspolicy-dependent

      The common production answer is both: managed for commodity traffic where price competition exists, self-hosted for provider-native features and internal policy. Keep one direct path per primary provider as the documented emergency route, and you can survive any single leg failing.

      Minimal architecture that holds up

      
      client → gateway (auth, routing, metering) → provider pool
                       ↓
                 request log (model, provider, tokens, price, latency)
                       ↓
              dashboards, budget enforcement, alerting
      

      Two rules keep it stable: the gateway must be stateless (so you can run three of them), and the log must be append-only and exportable (so leaving is possible).

      Where these numbers come from

      The market-versus-list figures are pulled live from the Cisoma pricing table, where each model row carries its own provider count — the reliability number that matters more than catalog size. For the request schema a gateway normalises, OpenAI's chat completions reference is the canonical shape, and Cloudflare's AI Gateway docs show the caching and logging layer of a similar design.

      Routing research is worth reading before you write a policy: RouteLLM covers learning-based routing between a cheap and an expensive model, and FrugalGPT frames the cost/quality cascade that most production routers approximate. The routing documentation and AI token economics cover the request-level details.

      FAQ

      Is an AI gateway the same as an API gateway?

      No. An API gateway routes HTTP to your services and knows nothing about tokens, model names, or streaming completions. An AI gateway is model-aware, multiplexes third-party providers, and meters inference cost per request.

      Does an AI gateway add latency?

      A same-region hop typically costs single-digit milliseconds on top of a request whose provider round-trip is tens to hundreds of milliseconds. The larger latency risk is a bad routing policy — sending interactive traffic to a slow-but-cheap deployment.

      Can I use one without changing my application?

      If it is OpenAI-compatible, yes: change base_url and api_key. Verify streaming, tool calls and error shapes before switching, since those are the usual breakages.

      Do I still need provider keys?

      With a marketplace you usually do not — the gateway holds supplier relationships. With a self-hosted proxy you do, and you own rotation and encryption. Decide which one your compliance posture prefers before you evaluate features.

      100M free tokens, one OpenAI-compatible API

      Every number on this page comes from the marketplace's own live offers. Point the OpenAI SDK at Cisoma and keep your code.

      Get 100M free tokens