Concepts

What is an LLM gateway?

An LLM gateway is a proxy that sits between your AI clients and the model providers they call. Clients send every request to one base URL, and the gateway holds the provider credentials, chooses the upstream route and records usage and cost. It turns many separate provider connections into one controlled, observable entry point.

What an LLM gateway does

Without a gateway, every AI client talks to its provider directly. Each tool carries its own provider key, each provider reports usage in its own format, and nothing ties the pieces together. A gateway puts one layer in the middle and gives that layer a handful of jobs.

  • One base URL. Clients point at the gateway instead of at each provider. Switching a model or a provider becomes a gateway setting, not an edit to every client.
  • Central credentials. Provider keys and account logins are stored once, on the gateway. They are not copied onto laptops, into shell profiles or into per-project config files.
  • Per-client keys. The gateway issues its own keys to the people, teams and tools that call it. Each key can be scoped, limited or revoked without touching the provider credential behind it.
  • Routing and fallback. The gateway decides which provider and model serves a request, by rule. When an upstream account is exhausted or failing, it can send the request somewhere else.
  • Usage and cost accounting. Because every request passes through one place, tokens and spend can be counted per key, user, model and provider.
  • Logging. Requests and responses can be recorded in one place, which makes failures and unexpected spend easier to trace.
  • Authentication caching. Validated client keys and upstream tokens can be reused rather than checked or refreshed on every call, which keeps the extra hop cheap.

How a request flows

A gateway is easiest to understand by following one request through it.

  1. A client sends a request to the gateway's base URL, signed with a gateway-issued key.
  2. The gateway checks the key, applies any limits attached to it, and works out who is calling.
  3. A routing rule picks the upstream provider, model and account.
  4. The gateway swaps in the stored provider credential and forwards the request.
  5. The response streams back to the client while the gateway records the tokens used, the estimated cost and the outcome.

The client never sees the provider credential, and the provider never sees the client's gateway key. Both sides talk to the gateway only.

When a gateway helps

A gateway earns its place once more than one of these is true.

  • Several AI tools or people share the same provider accounts.
  • You want to know what each tool, person or project costs, not just the monthly provider total.
  • Provider credentials should live in one place instead of on every machine.
  • You want to change models or providers without reconfiguring every client.
  • You need spend limits for individual keys or teams.

For a single developer with one tool and one account, a gateway may add more than it removes. The value grows with the number of clients, accounts and people involved.

Trade-offs to weigh

A gateway is one more component, and it sits on the path of every request.

  • A new dependency. If the gateway is down, the clients behind it cannot reach their providers. It needs to be run and kept up.
  • Added latency. Every request takes an extra hop. The cost is usually small next to model response time, but it is not zero.
  • Concentrated trust. The gateway handles prompts, responses and provider credentials, so who can reach it and what it logs matter.
  • A translation layer. Clients speak a provider's API shape to the gateway, so the gateway has to keep supporting the shapes its clients use.

None of these rule a gateway out. They are the questions to answer before putting one in front of your tools.

How memtrunk approaches it

memtrunk is a unified model proxy and admin console for Claude Code, Codex CLI and Antigravity CLI. It is the layer described above, plus a console for managing it. These are the parts of that picture that matter most for day-to-day use.

  • One address, several protocols. Clients send requests to one memtrunk address. It serves Anthropic Messages, OpenAI Chat Completions and OpenAI Responses routes, plus a Gemini-style REST route that is backed by Antigravity accounts. Use Claude Code with an LLM gateway shows the setup for one client.
  • Per-key spend limits. Each API key can carry monthly or daily USD caps and a monthly token cap, checked before a request is forwarded. A key at its cap gets an HTTP 429. Spend caps and budgets for AI coding agents covers the details and where the limits do not apply.
  • Usage and cost for every request. Each request is recorded with its provider, model, API key, user, session and agent, and cost is estimated from configured prices. The Usage page breaks spend down from there.
  • Request logs. Request headers and bodies are redacted by default, and logs are kept for 7 days by default. Both are instance settings.
  • Attribution per tool call. Each tool call is attributed to the agent or sub-agent that made it, with an error classification, so a failure points to the part of the work that caused it.
  • Server-enforced access. Role-based access is enforced on the server, with member, org admin and read-only auditor roles, rather than only hidden in the interface.
  • Memory, once enabled. Memory is off by default. Once it is enabled, it works automatically for Claude traffic that goes through the proxy. Other clients, such as Codex CLI, use the MCP server. See Persistent memory for Claude Code and Codex CLI.

For the full capability list, see the features page. For how access control and credential handling work, see security.