News KrakenD 3.0 Is Here: AI Router, Semantic Cache, and On-the-Fly Stream Manipulation News What Is an AI Gateway? Architecture, Controls and Use Cases News KrakenD CE 3.0.3, EE 3.0.3 and EE 2.13.13 Update Released News CVE-2026-98432: Linux Kernel Flaw Exposing KrakenD on Unpatched Hosts

Technical Insights & Best Practices

10 min read

What Is an AI Gateway? Architecture, Controls and Use Cases

by Toni Pinel

An AI gateway is a centralized control layer that manages traffic between applications and AI services, including large language models (LLMs).

It routes model requests, enforces security policies, controls usage, and provides observability across AI workloads.

For platform engineering teams, the challenge is maintaining consistent controls as applications, models, providers, and traffic volumes increase.

McKinsey’s August 2026 State of AI survey found that approximately 20% of respondents reported that AI operating costs, including token costs, constrained their organization’s AI usage.

An AI gateway helps address these operational challenges by providing a common enforcement point for AI traffic.

What Is an AI Gateway and Why Do Platform Teams Use It?

An AI gateway is a specialized API traffic management layer that connects applications to AI models while enforcing routing, access, security, and consumption policies.

An LLM gateway is the more specific term for a gateway focused on language models. Both terms often overlap in enterprise AI architecture.

Without centralized controls, applications may independently manage provider credentials, retries, authentication, usage tracking, and error handling.

Platform teams introduce an AI gateway to standardize these responsibilities and reduce duplicated operational logic.

Its primary responsibilities include:

  • LLM routing: selecting authorized models and endpoints according to defined policies.
  • Security enforcement: authenticating callers and protecting access to AI services.
  • AI governance: applying consistent usage, data-handling, and policy controls.
  • Observability: monitoring request behavior, latency, errors, and available token metrics.
  • Cost management: enforcing quotas and attributing AI consumption to applications or tenants.

An AI gateway does not train models or replace inference infrastructure. It governs how applications access those services.

Where Does an AI Gateway Fit in LLM Architecture?

An AI gateway operates between client applications and model endpoints. It can extend an existing API gateway or form a separate infrastructure component.

Two logical responsibilities define its architecture: the control plane determines policies, while the data plane processes requests according to those policies.

These responsibilities do not necessarily require physically separate components.

AI gateway between applications and LLM providers, with control plane and data plane

How Does an AI Gateway Process an LLM Request?

  1. Authentication: identify the calling application, user, or tenant.
  2. Policy evaluation: verify permissions, quotas, and applicable request restrictions.
  3. Model selection: choose an approved endpoint according to routing rules.
  4. Request forwarding: transmit the request using the required provider interface.
  5. Response processing: handle streaming, errors, and configured response controls.
  6. Telemetry: capture request timing, routing results, failures, and usage information.

Lifecycle of an LLM request through an AI gateway

This request lifecycle establishes the relationship between architecture, security, routing, and observability.

Trust boundaries remain essential. Application identity, provider credentials, and tenant permissions must be validated rather than accepted from untrusted request metadata.

How Does an AI Gateway Manage LLM Routing and Reliability?

LLM routing determines which model or provider receives an inference request. Routing rules may consider permissions, model capabilities, availability, or application requirements.

Provider abstraction allows applications to communicate through a stable interface while infrastructure teams manage underlying endpoints.

However, model features, tokenization, streaming formats, and supported operations can differ. An AI gateway does not automatically eliminate every compatibility issue.

Failover, Fallback, Retries, Streaming, and Caching

  • Failover: redirects eligible requests when a selected provider fails or a configured classifier cannot select an endpoint.
  • Fallback: provides a default route for requests that do not match earlier routing conditions.
  • Retries: repeat suitable failed operations while respecting timeout and duplication risks.
  • Streaming: forwards generated output incrementally to reduce perceived response delay.
  • Caching: reuses appropriate responses to avoid unnecessary model execution.

Failover and fallback solve different problems. In KrakenD’s AI Router, configured failover does not automatically handle requests that match no route.

A final route without conditions can handle unmatched requests. Without that route, the gateway returns an error when no routing rule matches.

Failover versus fallback in AI gateway routing

Failover also cannot guarantee recovery after a response has partially streamed. Different models may produce different outputs for equivalent requests.

Semantic caching matches requests by meaning rather than exact text. Its effectiveness depends on similarity thresholds, response suitability, and tenant isolation.

KrakenD Enterprise implements semantic caching using an Open Neural Network Exchange (ONNX) embedding model and Redis storage. Configurable cache partitioning helps separate responses by user or tenant.

How Does an AI Gateway Enforce Security and AI Governance?

AI gateway security combines traditional API protection with controls adapted to LLM traffic, such as prompt inspection and model-specific access restrictions.

AI governance establishes rules governing who can use AI resources, what operations are permitted, and how usage decisions are recorded.

Key security controls include:

  • Authentication and authorization: verify identities and restrict access to approved models or operations.
  • Credential management: protect provider API keys and limit credential exposure.
  • Prompt guardrails: inspect incoming requests for defined unsafe patterns or policy violations.
  • Data protection: apply configured validation, masking, and redaction rules.
  • Audit controls: record relevant access and policy decisions without exposing unnecessary sensitive content.

The OWASP Top 10 for LLM Applications 2025 identifies prompt injection, sensitive information disclosure, and unbounded consumption as important security risks.

Guardrails can mitigate selected threats but cannot guarantee complete protection against prompt injection or unsafe model behavior.

In KrakenD Enterprise, Prompt Guard evaluates incoming request bodies using predefined patterns, regular expressions, Common Expression Language (CEL) policies, or external classifiers.

Response validation and masking require appropriate response-processing controls. They should not be confused with the incoming-request checks performed by Prompt Guard.

Provider credentials can be managed through centralized configuration. KrakenD recommends injecting sensitive credentials through environment variables rather than storing them directly in configuration files.

Governance also requires application-level permissions, organizational procedures, and appropriate controls over downstream tools.

Self-hosting the gateway does not guarantee that prompts remain local. Data residency depends on the selected model endpoints and the entire request path.

How Does an AI Gateway Improve Observability and Cost Control?

AI gateway observability makes model traffic measurable through request metrics, logs, and distributed traces.

OpenTelemetry defines semantic conventions for generative AI telemetry, including model identification, request duration, and token usage when available.

KrakenD can reuse its existing OpenTelemetry infrastructure to monitor AI backends. Specific token, cost, or tenant-level measurements depend on the configured instrumentation and available usage data.

Operational monitoring should connect technical measurements with application, tenant, and model identifiers.

Essential AI Gateway Metrics

  • Latency: median and percentile response times, including p95 latency.
  • Streaming performance: time to first token and completion duration.
  • Reliability: error rates, timeouts, and successful failover attempts.
  • Token consumption: available input and output token counts by workload.
  • Policy enforcement: rejected requests and quota exhaustion events.

Token counts become cost estimates when combined with applicable pricing rules. They do not necessarily equal final provider charges.

Rate limits constrain request frequency, concurrency limits control simultaneous operations, and token quotas restrict measured consumption.

Token quotas improve budget predictability but do not always guarantee a hard spending cap.

With response-based token accounting, a request can exceed the remaining quota before its final consumption is recorded. Subsequent requests can then be blocked until the quota is replenished.

Actual spending still depends on usage patterns, provider pricing, billing behavior, and the configured enforcement strategy.

AI Gateway vs. API Gateway vs. LLM Proxy: What Is the Difference?

These technologies share traffic-management capabilities, but their primary responsibilities differ.

TechnologyPrimary responsibility
API gatewayManages general API authentication, routing, transformation, rate limiting, and observability.
LLM proxyForwards model requests and may provide provider abstraction or additional controls.
AI gatewayAdds AI-aware policies, routing, token management, and operational visibility.
Model servingExecutes inference workloads rather than primarily controlling application access.

The categories are not mutually exclusive. An API gateway with AI-specific capabilities can operate as an AI gateway without introducing another gateway layer.

When Do You Need an AI Gateway?

An AI gateway becomes valuable when centralized control provides more operational benefit than maintaining separate integrations.

A direct model API integration may be sufficient for a small prototype with limited access requirements and one application.

Consider an AI gateway when:

  • Multiple applications or teams access shared AI infrastructure.
  • Different tenants require separate model permissions and usage quotas.
  • Workloads use several models or require controlled failover.
  • Security policies must be enforced consistently.
  • Operations teams need centralized telemetry and consumption reporting.
  • Production systems require repeatable configuration and deployment practices.

Decision tree to know when you need an AI gateway

No universal traffic threshold determines when an AI gateway is necessary. Architecture complexity, security requirements, and operational accountability matter more.

How Should Platform Teams Evaluate an AI Gateway?

Evaluation should begin with explicit technical requirements and realistic production workloads.

A useful framework compares five dimensions:

  • Compatibility: supported model interfaces, streaming formats, and provider authentication.
  • Security: identity enforcement, policy controls, credential handling, and tenant isolation.
  • Reliability: timeout behavior, failure recovery, and operational resilience.
  • Observability: metrics, traces, token accounting, and workload attribution.
  • Deployment: infrastructure requirements, automation, scalability, licensing, and operating costs.

Performance testing should compare equivalent direct model requests with gateway-mediated requests under the same load and network conditions.

Measure gateway-added latency separately from model inference time. Record concurrency, throughput, error rates, and time to first token.

Cost evaluations should include gateway infrastructure, model consumption, licensing, and the operational effort needed to maintain the system.

Example: Managing a Multi-Tenant LLM Application

Consider a customer-support application serving multiple business customers. Each tenant has different model permissions, traffic volumes, and usage allowances.

Without centralized enforcement, application services must independently implement tenant restrictions, provider selection, and consumption tracking.

With an AI gateway, the application submits requests through a shared endpoint.

Multi-tenant LLM application routed through an AI gateway

The gateway authenticates the caller, checks tenant policies, selects an authorized model, and forwards the request.

If the selected provider fails, configured failover rules determine whether an alternative endpoint can handle the request.

If no routing condition matches, a configured fallback route can select a default provider. Without that route, the request fails.

Telemetry records model selection, request duration, errors, and available token usage. Platform teams can then evaluate reliability and consumption by tenant.

Usage quotas enforce tenant allowances, while response-based accounting requires consideration of potential quota overruns.

The main benefit is consistent, measurable control rather than a guaranteed reduction in inference costs or an improvement in model accuracy.

How Does KrakenD Enterprise Provide AI Gateway Capabilities?

KrakenD Enterprise extends API gateway infrastructure with capabilities designed for LLM traffic, security policies, and AI governance.

API Gateway and AI Gateway capabilities are distributed through the same Enterprise executable. Access to AI-specific features depends on the entitlements included in the Enterprise license.

These AI Gateway capabilities should not be confused with the general API management features available in KrakenD Community Edition.

KrakenD Enterprise offers several relevant mechanisms:

  • AI Router: selects providers through ordered rules, policy gates, and optional classifiers. Failover handles configured provider or classifier failures, while a final unconditional route handles unmatched requests.
  • Provider Inventory: centralizes model endpoint definitions and credentials, with environment variables recommended for sensitive values.
  • Prompt Guard: inspects incoming requests using predefined patterns, regular expressions, CEL policies, or external classifiers.
  • Token Quotas: supports usage allowances and consumption governance, subject to response-based accounting limitations.
  • Semantic Cache: reuses semantically similar responses using ONNX embeddings, Redis storage, and configurable cache partitioning.
  • OpenTelemetry Integration: supports monitoring and tracing across API and AI traffic using configured telemetry components.
  • MCP Server: a Model Context Protocol (MCP) server that exposes existing services as tools for AI agents, with authentication, authorization, and tool filtering by audience.

KrakenD can run in self-hosted environments, allowing organizations to manage deployment and configuration through their existing infrastructure practices.

Additional dependencies may be required for selected capabilities, including Redis and an ONNX embedding model for semantic caching or an external service for classifier-based policies.

By managing APIs and AI workloads through the same gateway infrastructure, platform teams can avoid duplicating common traffic controls.

Explore KrakenD’s AI Gateway or review the Enterprise documentation to evaluate the available features and deployment requirements.

Frequently Asked Questions About AI Gateways

These are the questions platform teams ask most often when they evaluate an AI gateway.

Can an AI Gateway Work with RAG Applications?

Yes. An AI gateway can control model requests generated by retrieval-augmented generation (RAG) applications. Document indexing, retrieval quality, and source validation remain separate responsibilities.

Does an AI Gateway Need a GPU?

No. An AI gateway primarily processes network requests and policies. GPU requirements depend on whether the organization also operates model inference or other compute-intensive AI services.

What Is the Difference Between an AI Gateway and an AI Firewall?

An AI firewall focuses on detecting or blocking unsafe AI interactions. An AI gateway has broader responsibilities, including routing, authentication, usage controls, and observability.

Conclusion: Why AI Gateways Matter for Platform Engineering

An AI gateway provides a common control layer for LLM traffic, connecting model routing, security enforcement, AI governance, observability, and usage management.

Its value depends on the complexity of the AI architecture and the controls required for reliable production operations.

Platform teams should define requirements, evaluate measurable behavior, and select infrastructure that supports their deployment and governance needs.

KrakenD Enterprise offers an integrated approach to managing API and AI workloads through self-hosted gateway infrastructure, AI-specific controls, and centralized operational policies.

Stay up to date with KrakenD releases and important updates