Respan: an Open Source Rust AI Gateway Built on Plugins

After a 100,000-line LiteLLM wrapper and an upgrade that broke production, Respan rewrote its gateway around an Nginx-style core. We walk through the request path, passthrough rules and the trade-offs of a pre-alpha plugin system.

Binary Buddies · 5 min read · 10 views

Most LLM gateways solve the same problem: call many model providers through one endpoint. The trouble starts when you need something the gateway was not built for. Per-organisation API key settings, custom routes, rate limits, a provider quirk nobody upstream cares about. You end up wrapping the gateway, then wrapping the wrapper, and eventually you are maintaining a second gateway by accident.

That is the situation the team behind Respan (YC W24) described in their Launch HN post. They had run a production gateway on LiteLLM since 2024, serving thousands of organisations. Their wrapper code grew past 100,000 lines. Then a routine LiteLLM upgrade introduced intermittent connection errors. They rolled back, never found the cause, and stopped upgrading LiteLLM directly. Since then they manually backport upstream fixes.

Their answer is a rewrite: an open source AI gateway in Rust with a deliberately small core, where providers, protocols, modalities and gateway features are all plugins. The architecture is worth looking at whether or not you adopt it, because it makes specific choices about where complexity should live.

Why the wrapper approach stopped working

The failure here is familiar to anyone who has built on a monolithic dependency. Each organisation on Respan's platform needed different API key settings, routes and limits. LiteLLM did not provide all of that, so the team added features around it. Each new requirement meant more code coupled to LiteLLM's internals, and the wrapper passed 100,000 lines.

The cost of that coupling showed up in January. A routine upgrade, the kind that should be a version bump and a deploy, caused intermittent connection errors in production. Intermittent is the worst kind of failure to diagnose, and the team says they still have not identified the cause. The practical result was a rollback and a policy change: no more direct upgrades, only hand-picked backports of upstream fixes.

Backporting by hand is a slow drift away from upstream. Every fix you skip widens the gap, and every fix you take has to be checked against 100,000 lines of code that upstream never saw. The team concluded that continuing to patch LiteLLM was not sustainable and that they needed to redesign the gateway themselves.

A core that only dispatches events

The design reference is Nginx. The Respan core is meant to be very small and responsible for one thing: dispatching events. It does not know about OpenAI, Anthropic or Gemini as special cases. It does not have fallbacks or PII redaction built in. It exposes public interfaces and runs whatever plugins are registered against them.

The stated goal is to make it easy to add features without breaking existing ones. In a monolithic gateway, adding a feature often means touching shared request-handling code, and that is where regressions come from. If the core stays small and stable, new behaviour lands as a new plugin rather than as an edit to code every other feature depends on.

This also changes who can extend the gateway. With a public plugin interface, a team that needs a custom routing rule or an internal provider can write it as their own plugin without forking the project. That is the problem the 100,000-line wrapper was trying to solve, approached from the opposite direction.

Everything is a plugin, including provider quirks

The plugin boundary covers more than most gateways expose:

  • Providers: OpenAI, Anthropic, Gemini and others.
  • Protocols: chat, realtime voice, MCP.
  • Modalities: images, videos.
  • Gateway features: smart routing, fallbacks and PII redaction, shipped as example plugins.

The detail that stands out is how providers are handled. According to the launch post, a provider is a short file; Mistral's is 22 lines. Provider quirks are plugins too, with nothing special about them. The example given is Groq putting token usage in its own field. That quirk is isolated and gets its own test.

This is the right place to put that kind of complexity. In many gateways, provider differences are handled by conditionals scattered through shared translation code, which makes it hard to tell what changed when an upgrade breaks something. A quirk with its own file and its own test can be reviewed, removed or fixed on its own. It is also the part of a gateway that churns most, since providers change response formats without asking anyone.

How a request moves through the gateway

The request path is described in four steps. First, an adapter takes each incoming HTTP or WebSocket connection and hands it to the first client format that recognises it. The client format is what the application speaks, for example the OpenAI chat API.

Second, that format exposes the request as a two-way stream of typed input and output events. Third, the core runs plugins in registration order. Each plugin can choose a provider, filter or wrap either stream, make additional calls, return a response directly, or refuse the request. Fourth, a provider format opens the upstream connection to the model provider.

Two consequences follow. Registration order matters, so a PII redaction plugin and a routing plugin need to be ordered deliberately, and you should treat plugin order as configuration you review. And because everything is a stream of events, the same model covers a one-shot HTTP completion and a long-lived bidirectional session such as realtime voice. The gateway does not need a separate code path for each.

Passthrough versus translation

Gateways usually lose information when they normalise requests. A provider adds a field, the gateway's internal schema has no slot for it, and it is silently dropped. Respan addresses this in two ways.

When the client and provider use the same format and no plugin modifies the payload, the original bytes and protocol-specific fields pass through unchanged. If your client speaks the OpenAI API and the request goes to OpenAI, the gateway is not rewriting it. Even when requests are parsed into the shared structure and client and provider share an API, provider-specific fields are preserved in their native format, so the gateway can write them back instead of dropping them.

When the formats differ, translation runs through shared types for messages, tool calls, tool results, streams and usage. That is where fidelity can suffer, and it is the path to test most carefully. The passthrough case is cheap and safe; the translation case is where you find out which fields your application relies on.

Cross-protocol calls: Realtime to Gemini Live, MCP for plain chat

The translation layer goes further than letting the OpenAI SDK call Claude or Gemini. The launch post says the gateway handles tools, images and reasoning protocols automatically. Two examples are given.

An application built on the OpenAI Realtime API can use Gemini Live through the gateway. The team is explicit that not every feature translates, which is the honest answer: two realtime voice protocols designed by different vendors will not map one-to-one. If you try this, inventory the Realtime features your app uses and verify each one against Gemini Live behind the gateway before switching traffic.

The second example is MCP. A simple chat application can use MCP tools configured in the gateway without implementing MCP itself. The gateway becomes the MCP client, and the application only sees ordinary tool calls in the chat protocol it already speaks. For teams that want tool access without adding MCP support to every client, that removes a real chunk of work.

Running it yourself

The gateway is open source at github.com/respanai/respan-gateway, dual-licensed under MIT or Apache-2.0. You do not need Respan's hosted platform. The documented path is to build it from source, add your provider keys, and change the base URL in a supported client. Your application keeps using the API it already speaks.

For extension work, the repository includes PLUGINS.md, which explains how to write a plugin and links to the plugins built so far. The team says turning those into an ecosystem is essentially their roadmap, and they are asking for plugins covering routing, tools, filtering, observability and security for agents.

The commercial side is the hosted platform, which runs the gateway for you and adds native observability, evals and unified billing. That split is common for open source infrastructure: the core is free and permissively licensed, and the operational extras are the product.

Where this does not fit, and what to watch

The most important fact is in the launch post itself: the gateway is pre-alpha. If you need a gateway in production this quarter, this is not it yet. Interfaces in a pre-alpha plugin system are likely to move, and every plugin you write against them is code you may have to revisit.

The plugin model also moves work onto you. A batteries-included gateway gives you fallbacks, routing and redaction as configuration. Here those ship as example plugins, and anything beyond them you build, test and order yourself. Teams that only need one endpoint for a few providers may find a monolithic gateway simpler to operate.

Watch the translation path. Passthrough is the safe case; cross-format calls, and especially cross-protocol realtime voice, are where behaviour differs and where the team itself says not everything translates. Watch plugin ordering, since plugins run in registration order and can refuse or rewrite requests. And note the irony in the origin story: the motivation was getting burned by a dependency upgrade. A small core reduces that risk only if the plugin interfaces stay stable, which is a promise a pre-alpha project has not yet had the chance to keep.

  • #AI gateway plugins
  • #LLM routing
  • #LiteLLM alternative
  • #MCP gateway
  • #Respan
  • #Rust LLM gateway

Comments

Add a comment
Sign in with Google to join the conversation