█

AI/TLDR

Buy me a coffee
Buy me a coffee

Invariant Gateway

An LLM proxy that observes and debugs what your AI agents are doing

Guardrails & SecurityOpen source
Language
Python
License
Apache-2.0
IN SHORT

What is Invariant Gateway?

Invariant Gateway is an open-source service from Invariant Labs that sits between your AI agent and its LLM provider. It acts as a proxy: instead of calling OpenAI, Anthropic, or Gemini directly, your client points its base URL at the Gateway, which forwards the request and records what happened. It sits in the Guardrails & Security category of the Evaluation & Production Ops tools and is open-source, written in Python and licensed Apache-2.0.

Overview

Invariant Gateway is an open-source service from Invariant Labs that sits between your AI agent and its LLM provider. It acts as a proxy: instead of calling OpenAI, Anthropic, or Gemini directly, your client points its base URL at the Gateway, which forwards the request and records what happened. The traces are stored in the Invariant Explorer so you can review them later.

It is meant for developers building agentic systems who need to see what their agents actually send and receive at runtime. Because it works at the LLM level, it captures normal chat completions, tool calls, and computer-use interactions without you having to rewrite your agent logic.

As a guardrail and observability tool, Gateway focuses on visibility and debugging. It supports the MCP protocol over standard I/O, Server-Sent Events, and Streamable HTTP, and forwards streaming responses, so it fits in front of agents that talk to both model APIs and MCP servers.

What it does

  • Single-line setup: point your LLM client's base URL at the Gateway and add one header, no code rewrite
  • Intercepts calls at the LLM level for debugging and analysis across providers
  • Captures tool calling and computer-use interactions, not just plain chat
  • MCP protocol support over standard I/O, Server-Sent Events, and Streamable HTTP
  • Forwards requests and streams responses to OpenAI, Anthropic, Gemini, and other providers
  • Stores and organizes runtime traces in the Invariant Explorer

Getting started

The quickest way to use Gateway is the hosted Explorer endpoint: keep your existing client, but change its base URL and add the Invariant-Authorization header. The example below uses the Anthropic client.

Point your client at the Gateway

Configure your Anthropic (or OpenAI/Gemini) client to send requests through the Gateway base URL, including your Invariant API key in the Invariant-Authorization header. Replace the dataset name with your own; it is created automatically if it does not exist.

pythonpython
from httpx import Client
from anthropic import Anthropic

client = Anthropic(
    http_client=Client(
        headers={
            "Invariant-Authorization": "Bearer your-invariant-api-key"
        },
    ),
    base_url="https://explorer.invariantlabs.ai/api/v1/gateway/{add-your-dataset-name-here}/anthropic",
)

Use your client as usual

Make calls exactly as you normally would. Gateway forwards each request to the provider, streams the response back, and records the trace in the Invariant Explorer.

Or run the Gateway locally

To self-host instead of using the hosted endpoint, pull and run the published Docker image. It serves the Gateway at http://localhost:8005/api/v1/gateway/.

bashbash
docker pull --platform linux/amd64 ghcr.io/invariantlabs-ai/invariant-gateway/gateway:latest
docker run -p 8005:8005 -e PORT=8005 --platform linux/amd64 ghcr.io/invariantlabs-ai/invariant-gateway/gateway:latest

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Debugging a multi-step agent by inspecting the exact prompts, tool calls, and responses it produced at runtime
  • Adding observability to an agent that uses MCP servers over stdio, SSE, or Streamable HTTP
  • Tracing and organizing LLM interactions across OpenAI, Anthropic, and Gemini from one place
  • Reviewing computer-use or tool-calling behavior when an agent does something unexpected

How Invariant Gateway compares

Invariant Gateway alongside other open-source guardrails & security tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
SkillSpector★ 28.3kSecurity scanner for AI agent skills that checks a skill for prompt injection, data exfiltration, privilege escalation and supply-chain risks before you install it.
Presidio★ 12.1kAn open-source framework for detecting, redacting, masking, and anonymizing personal data (PII) across text, images, and structured data using NER models, regex, and rule-based recognizers.
Failproof AI★ 10.5kA hook-based CLI and Rust daemon that listens to every event from 12 agent harnesses such as Claude Code, Codex and Cursor, and blocks, warns or steers the agent with one policy API, with optional cloud tracing and failure audits.
Guardrails AI★ 7.7kA Python framework that wraps LLM calls with composable input/output validators (from the Guardrails Hub) to check structure, type, and safety risks before responses reach users.
NeMo Guardrails★ 7.6kNVIDIA's toolkit for adding programmable rails to LLM chat apps, using the Colang language to control dialog flow and block jailbreaks, prompt injection, and off-topic answers.
BLA (Blind LLM Agents)★ 7.3kAn open-source CLI and MCP server that hardens the apps, WASM modules, databases and model files you ship so AI reverse-engineering agents such as REA hit resource budgets and follow decoys, without changing runtime behaviour.
dcg (Destructive Command Guard)★ 6.4kA Rust pre-tool hook for coding agents that inspects each shell or git command before it runs and blocks the destructive ones, with an explanation and a safer alternative.
Invariant Gateway★ 83An LLM proxy that observes and debugs what your AI agents are doing