# Invariant Gateway

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

- Category: Evaluation & Production Ops / Guardrails & Security
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/invariantlabs-ai/invariant-gateway
- Website: https://invariantlabs.ai
- Canonical page: https://ai-tldr.dev/tools/invariant-gateway/

## In short

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.

1. 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.

```python
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",
)
```

2. 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.

3. 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/.

```bash
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
```

## 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
