Materials / Practices

LLM gateway and on-premise models: a closed circuit for AI agents

Once more than a handful of engineers use agents, someone will ask where the code goes, who holds the keys and what it costs. An LLM gateway answers all three in one place. This guide covers what a gateway does, how to choose one, how to put Claude Code behind it, and when a model on your own hardware makes sense.

9 min read17 Nov 2026Ilia Poliakov

What a gateway is

An LLM gateway is a proxy between your agents and the model providers. Every request from a developer's agent, a CI job or an internal tool goes to the gateway; the gateway authenticates it, records it, applies policy and forwards it to a provider. The provider's keys stay on the gateway. Developers hold gateway credentials instead.

Without one, a team ends up with dozens of personal API keys, spend that nobody can attribute until the invoice arrives, and no record of what code left the building. That is why a gateway is usually the first thing a security function asks for before agents go beyond a pilot, and why it belongs in the adoption plan early rather than as a retrofit.

What a gateway does

FunctionWhat it gives you
Key isolationProvider keys never reach laptops. Each person or service gets a virtual key that can be revoked alone; offboarding is one revocation.
Logging and auditWho sent a request, when, to which model, with how many tokens. Some teams also keep prompts and responses for compliance; decide that deliberately, since they contain source code.
Budgets and rate limitsLimits per team, project or person. An agent stuck in a loop hits its budget instead of running all weekend.
RoutingSend each request to the right model or endpoint: a cheaper model for simple work, a stronger one by default, a restricted endpoint for sensitive repositories, a fallback when a provider fails.
FilteringMask secrets and personal data in requests before they leave, or block requests that match a pattern.
Provider independenceChange the provider or region in the gateway's configuration without touching developer machines.

Anthropic's own documentation lists much the same set for Claude Code: credentials kept server-side, usage attributed by developer or team, budgets and rate limits in one place, audit logging, and provider switching (Claude Code: LLM gateways). It also names the cost: the gateway becomes infrastructure you operate, and it has to keep up with new client capabilities or features break.

The closed circuit

Put together, the arrangement looks like this:

developers' agents      CI agents          internal tools
(Claude Code, IDEs)     (review, tests)    (scripts, bots)
        \                    |                  /
         \  virtual keys     |                 /
          v                  v                v
      +------------------------------------------+
      |               LLM gateway                |
      |  auth - logs - budgets - masking - routes|
      +------------------------------------------+
           |                           |
           v                           v
  cloud provider account        model on your own
  (approved region, your        hardware (for code
  contract and retention)       that may not leave)

Two rules make it a circuit rather than a suggestion. First, the gateway is the only path: configuration is distributed centrally and machines refuse other endpoints. Second, security routing outranks cost routing: a repository marked sensitive goes to its restricted endpoint even when a cheaper one is available.

Choosing a gateway

Several products fill the role. A non-exhaustive list:

Judge them on the same handful of questions:

QuestionWhy it matters
Which API formats does it expose and forward faithfully?Claude Code speaks the Anthropic Messages format; other agents speak OpenAI's. A gateway that translates badly breaks features silently.
Virtual keys per person and per service?Attribution and revocation depend on it.
Budgets with alerts, per team and per project?A budget nobody hears about until it is exhausted stops work instead of warning.
Can logs be exported to your SIEM and cost tools?Audit and chargeback happen there, not in the gateway's screen.
Does it run with no outside connection?Required for air-gapped networks and the strictest data rules.

Putting Claude Code behind the gateway

Claude Code works with any gateway that exposes a supported API format. Two environment variables point it there: ANTHROPIC_BASE_URL, the gateway's address, and a credential, either ANTHROPIC_AUTH_TOKEN (sent as Authorization: Bearer) or ANTHROPIC_API_KEY (sent as x-api-key). A credential that rotates or comes from a vault goes through an apiKeyHelper command instead (connect Claude Code to an LLM gateway).

For a team, do not ask each developer to export variables. Distribute them in a managed settings file, so every machine gets the same address and nobody has to configure anything:

{
  "env": {
    "ANTHROPIC_BASE_URL": "https://llm-gateway.example.internal"
  },
  "apiKeyHelper": "/usr/local/bin/get-gateway-key",
  "allowedProviders": ["customEndpoint"]
}

The allowedProviders entry is what closes the circuit on the client: with it set to ["customEndpoint"] and the base URL in the same managed file, Claude Code refuses a session pointed anywhere else, including Anthropic directly or a developer's own proxy (it requires a recent Claude Code version; see the gateway docs). The rollout sequence, deploy the gateway, issue a credential per developer, distribute configuration, have each developer check /status, is spelled out in rolling out an LLM gateway.

On the gateway side, the checks that catch most problems (gateway compatibility guide):

Two side effects to tell developers about. While a gateway credential is active, requests use it instead of a personal claude.ai subscription, so billing is per token to whoever owns the gateway's provider account. And features tied to a claude.ai identity, such as Remote Control, are unavailable behind a gateway credential. CI agents follow the same pattern: the Claude Code GitHub Action reads ANTHROPIC_BASE_URL from the workflow's environment.

When a model on your own hardware is warranted

Some code should not go to any cloud model: code under a customer NDA that forbids it, systems that process personal data where your jurisdiction's data-protection law (GDPR, for example) and your contracts rule out the transfer, trade secrets, and networks with no internet access at all.

For those, teams run open-weight code models on their own GPUs, served through vLLM or SGLang, which expose an OpenAI-compatible API the gateway can route to. Be clear about the limits before committing:

There is a middle path that settles many cases. Claude is offered through Amazon Bedrock, Google Cloud's Agent Platform and Microsoft Foundry, and Claude Code can reach those through the gateway with its provider-specific variables (ANTHROPIC_BEDROCK_BASE_URL with CLAUDE_CODE_USE_BEDROCK=1, and the equivalents). Code then goes to a cloud account and region your company already has a contract and retention terms for, which is often what the security function actually needed.

A routing policy, written down

Write the routing rules as configuration the security function can read and sign off. The shape below is illustrative; each gateway has its own syntax.

# Rules are evaluated top to bottom; the first match wins.
# Security rules come before cost rules.
routes:
  - match: { repo_tag: nda }
    target: onprem-coder            # never leaves the building
  - match: { repo_tag: personal-data }
    target: cloud-claude-eu         # provider account in an approved EU region
  - match: { client: research-bot }
    target: fast-cheap-model
  - match: {}                       # everything else
    target: cloud-claude-default
    fallback: cloud-claude-eu

budgets:                            # monthly, per team
  payments-team: { tokens: 400_000_000, alert_at: 80% }
  web-team:      { tokens: 150_000_000, alert_at: 80% }

logging:
  keep: [user, team, model, tokens, latency, session_id]
  prompts: off                      # turn on only with a retention decision

Review this file like code. When a team asks for a new model or a bigger budget, the change is a pull request, with the reason in its description.

Questions

What is an LLM gateway, in one sentence?

A proxy between your agents and the model providers that holds the provider keys, logs every request, enforces budgets and routes each request to the right model or endpoint.

Can Claude Code run through our corporate gateway?

Yes, if the gateway exposes the Anthropic Messages format (or a supported cloud provider's format). Set ANTHROPIC_BASE_URL and a credential, distribute them through managed settings, and pin allowedProviders so sessions cannot bypass it.

Do we need a gateway if we use only one provider?

Usually yes. Audit logs, per-team budgets and revoking one person's access without rotating a shared key are worth having with a single provider too.

Which local model should we run?

Whichever open-weight code model performs best on a sample of your own tasks on hardware you can afford; the leaders change every few months. Measure on your repositories, keep tasks for it small and well specified, and remember that Claude Code itself is not supported on non-Claude models.