Getting Started With Gateway
Invariant Gateway is a lightweight zero-configuration service that acts as an intermediary between AI Agents and LLM providers (such as OpenAI and Anthropic).
Gateway automatically traces agent interactions and stores them in the Invariant Explorer, giving you insights into what your agents are doing. This enables you to easily observe and debug your agent applications without any code changes.
Features
- Single Line Setup: Just change the base URL of your LLM to the Invariant Gateway.
- Intercepts agents on an LLM-level for better debugging and analysis.
- Tool Calling and Computer Use Support to capture all forms of agentic interactions.
- Seamless forwarding and LLM streaming to OpenAI, Anthropic, and others.
- Stores and organize runtime traces in the Invariant Explorer.
Getting Started as a Security Admin
Looking to observe and secure AI agents in your organization? Read our no-code quickstart guides below, for configuring different agents directly with the Invariant Gateway.
This way, you can keep track of your organization's agents, without having to change their code.
If you are interested in deploying your own dedicated instance of the Invariant Gateway, see self-hosting.
Getting Started as Developer
To quickly integrate your agentic application with the Gateway, it is enough to rely on our hosted instance which automatically traces your agent's LLM calls:
from swarm import Swarm, Agent
from openai import OpenAI
from httpx import Client
# === Invariant integration ===
client = Swarm(
client=OpenAI(
# redirect and authenticate with the Invariant Gateway
http_client=Client(headers={"Invariant-Authorization": "Bearer <your-token>"}),
base_url="https://explorer.invariantlabs.ai/api/v1/gateway/<your-dataset-id>/openai",
)
)
# === Agent Implementation ===
# define a tool
def get_weather():
return "It's sunny."
# define an agent
agent = Agent(
name="Agent A",
instructions="You are a helpful agent.",
functions=[get_weather],
)
# run the agent
response = client.run(
agent=agent,
messages=[{"role": "user", "content": "What's the weather?"}],
)
print(response.messages[-1]["content"])
# Output: "It seems to be sunny."
To learn how to use the Gateway with other LLM providers and agent frameworks, see the following sections: