Portkey AI Gateway: Routing, Guardrails and Reliability for LLMs

Portkey AI Gateway: Routing, Guardrails and Reliability for LLMs

Portkey AI gateway is an open-source LLM gateway that routes requests to more than 200 language, vision, audio and image models through one fast, OpenAI-compatible API. The central question is what it adds beyond a simple proxy, and the short answer is reliability and control: automatic retries, fallbacks, load balancing, guardrails and caching, all configured in JSON and applied at the gateway instead of in every application.

Most LLM integrations start simply and grow messy. One application talks to one provider, then a second provider is added for a cheaper model, then a fallback is bolted on after the first outage, then someone adds a cache to cut costs. Each addition lives in application code, where it is hard to test and easy to forget.

Portkey AI gateway moves all of that into one layer, so the reliability logic is written once and shared by every application behind it.

Key takeaways

  • Portkey AI gateway is a lightweight, open-source TypeScript gateway for 200+ LLMs, under the MIT licence.
  • One OpenAI-compatible API reaches every provider, so applications change models by changing configuration.
  • Fallbacks, automatic retries, load balancing and request timeouts are configured in JSON per request.
  • Guardrails check inputs and outputs against pre-built or custom rules before they reach users.
  • Semantic and simple caching cut cost and latency, but must be scoped so users never see each other’s answers.
  • The gateway runs on Node.js, Bun, Docker or Cloudflare Workers, and also exists as a hosted service.

What the Portkey AI gateway is

The Portkey AI gateway is a small TypeScript service that sits between your applications and your LLM providers. It presents a single OpenAI-compatible API, so any client that works with OpenAI can call any of the 200+ supported models through it, and it extends that API with reliability features that the plain provider APIs do not offer. It is open source under the MIT licence, and the same gateway powers Portkey’s hosted service, which processes billions of tokens a day in production.

The gateway is deliberately tiny and fast: the project describes it as having a footprint measured in kilobytes and latency under a millisecond for its own processing. That matters because a gateway sits on the critical path of every request; if it is slow or heavy, it becomes the bottleneck it was meant to remove. It can also run at the edge on Cloudflare Workers, routing and retrying requests close to users without running servers.

Our guide to AI gateway architecture explains where a gateway belongs in the stack, and Portkey is one of the lightest ways to put one there.

Configuration travels with the request. Routing rules, retries, fallbacks and guardrails are defined in a gateway config, a JSON document sent with the request or referenced by the client, so different applications can use different reliability policies through the same gateway. Best for: teams that want production-grade reliability for LLM calls without building retry, fallback and guardrail logic into every application.

Reliability: fallbacks, retries and load balancing

Fallbacks are the gateway’s most important feature. You define a prioritised list of providers or models, and if the first one fails, the gateway automatically tries the next. You can specify which errors trigger a fallback, so a rate limit moves to another provider while a malformed request fails fast instead of being retried pointlessly.

That distinction matters: blind retries turn a small problem into a large bill.

Automatic retries handle transient failures. The gateway can retry a failed request up to five times, spacing attempts with exponential backoff so it does not hammer a struggling provider. Combined with fallbacks, the pattern is retry briefly on the same provider, then fall back to another provider, then fall back to another model, each step governed by the config rather than by hope.

Load balancing spreads traffic across multiple API keys or providers using weights you choose, which keeps any single key or provider from becoming a bottleneck and improves availability when one provider slows down. Request timeouts add the final guard: a granular timeout terminates requests that exceed a set duration, so one slow model cannot hold a worker or a user waiting indefinitely. Best for: production applications where a provider outage or a slow model must not become a user-facing failure.

Comparing Portkey with other gateway options

Option Deployment Main strength Main risk
Portkey AI gateway Self-hosted or edge, MIT licence Tiny and fast, JSON-configured reliability Advanced features such as RBAC are paid
LiteLLM gateway Self-hosted proxy, MIT licence Virtual keys and spend tracking built in Heavier footprint than Portkey
Hosted unified API Managed service, one key Nothing to run or maintain Traffic passes through a third party
Direct provider SDKs One SDK per provider Full access to each provider’s features Reliability logic duplicated in every app
API management gateway General-purpose gateway Mature rate limiting and auth controls Not designed for LLM-specific concerns
A control room style dashboard showing traffic flowing through a central hub to several model services
A gateway is the control point for LLM traffic: routing, retries and guardrails all happen in one place.

Guardrails and safe outputs

Guardrails in Portkey verify inputs and outputs against checks before they reach a model or a user. The gateway ships with more than 40 pre-built guardrail checks, and you can add custom ones or plug in partner tools for content classification. A guardrail can reject a prompt that contains sensitive data, block a response that contains banned content, or require a response to match an expected format before it is returned.

The plugin system extends this further. Plugins run at hooks in the request lifecycle, such as before the request is sent or after the response arrives, so custom logic can inspect, modify or reject traffic at exactly the right point. That is how teams add organisation-specific rules, such as blocking certain topics, redacting patterns from prompts or enforcing JSON output, without changing application code.

Guardrails are not a substitute for evaluating your model or for controlling what data your applications send. A guardrail can catch known bad patterns, but it cannot judge whether an answer is correct, and it cannot protect data that was already sent to a provider outside the gateway. Use guardrails as one layer of defence, alongside prompt design, evaluation and access control.

Our guide to jailbreak defence covers the broader problem guardrails are part of. Best for: applications exposed to untrusted input, where a bad prompt or a bad response must be stopped before it reaches a user.

Caching, keys and observability

Portkey supports two kinds of caching. Simple caching serves the same response for an identical repeated request, which suits deterministic or repeated queries. Semantic caching goes further, serving a cached response for a new prompt that means the same thing as a cached one, which catches the many ways users ask the same question.

Both cut cost and latency, but both need scoping: a cache must never serve one user’s answer to another user, and it must never serve a stale answer where freshness matters.

Key management in the open-source gateway is deliberately simple: clients send their provider key and the routing config with each request. That keeps the gateway stateless and tiny, but it means the gateway does not store keys for you. Virtual keys, stored logs, spend analytics, semantic caching and role-based access control are part of the hosted plans, and the enterprise tier adds single sign-on, audit logs, budgets and private deployment.

Teams choosing the open-source gateway should understand that boundary before they depend on features that live on the other side of it.

Observability comes from logging and tracing every request that passes through the gateway. Because all traffic flows through one point, the gateway is the natural place to record latency, token use, error rates and fallback frequency per model and per provider. Those numbers are the evidence you need when a provider’s quality slips or a model’s cost drifts.

Best for: teams that need request-level visibility across many models and providers without instrumenting each application separately.

Running Portkey in production

Getting started takes minutes: the gateway runs on Node.js, Bun, Docker or Cloudflare Workers, and the quickstart has it listening locally with a single command. That ease of start is genuine, but production use still needs the usual discipline. Run the gateway behind a stable address your applications can reach, keep its configuration in version control, and make sure a gateway restart does not lose anything your applications depend on.

Because the open-source gateway is stateless, high availability is straightforward: run more than one instance behind a load balancer, and a single instance failing is a non-event. The harder question is what happens when the gateway is unreachable. Decide in advance whether applications should fail closed, fail open to a direct provider call, or queue and retry, and test that behaviour rather than discovering it during an incident.

Keep the gateway updated and watch its release history. The project has moved quickly, with a 2.0 release merging the enterprise gateway into open source, and the hosted product’s direction has changed as the company evolved. Before adopting any open-source gateway for the long term, check that its maintenance pace and roadmap match your appetite for keeping up.

Best for: teams that value a small, fast gateway and are comfortable managing the operational pieces around it themselves.

Portkey AI gateway checklist

  • Every production LLM call flows through the gateway, not around it.
  • Fallbacks are configured for every model, with the triggering errors chosen deliberately.
  • Retries use exponential backoff and stop before they amplify an outage.
  • Load balancing weights reflect the capacity and cost of each provider.
  • Request timeouts are set so a slow model cannot block a worker indefinitely.
  • Guardrails cover both prompts and responses, with custom rules for your own risks.
  • Caching is scoped per user or per use case, and never serves stale or cross-user answers.
  • Gateway configuration is stored in version control and reviewed like code.
  • More than one gateway instance runs behind a load balancer in production.
  • Latency, errors and fallback frequency are monitored per model and per provider.

Frequently asked questions

Is the Portkey AI gateway really free?

The open-source gateway is MIT licensed and free to self-host, including its unified API, retries, fallbacks, load balancing and guardrail checks. Hosted plans add stored logs, spend analytics, semantic caching and access control, so check which features your use case actually needs.

How is Portkey different from LiteLLM?

Both are open-source, OpenAI-compatible gateways, but they emphasise different things. Portkey is a small TypeScript service built around JSON-configured reliability and guardrails, with an edge deployment option. LiteLLM emphasises virtual keys, budgets and spend tracking through a central proxy.

Many teams evaluate both against their own priorities.

Can Portkey call models other than text models?

Yes. The gateway supports vision, audio, text-to-speech, speech-to-text and image generation models through the same unified API, so one gateway can serve every model type your applications use.

Do I need the hosted plan for guardrails?

No. Guardrail checks and the plugin system are part of the open-source gateway. The hosted plans add the management layer around it: stored logs, analytics, semantic caching, role-based access control and single sign-on.

What is the MCP gateway in Portkey?

It is a control plane for managing Model Context Protocol servers across an organisation, with a single authentication layer, access control and observability for the tools your agents use. It is a separate concern from routing model requests, but it sits naturally beside the AI gateway.

Should the gateway hold my provider keys?

In the open-source gateway, clients send their provider key with each request, so keys should be managed by your own secrets handling and rotated regularly. Our guide to model endpoint protection covers how to secure the API layer behind your models.

Latest articles

Scroll to Top