Luca Beurer-Kellner fd07112d82 patching
2025-02-17 23:24:27 +01:00
2025-02-17 23:24:27 +01:00
2025-02-06 11:26:23 +01:00
2025-02-17 20:18:21 +01:00
2025-02-17 20:18:21 +01:00
2025-02-12 09:49:28 +01:00
2025-02-13 15:46:09 +01:00

Invariant Proxy

Invariant Proxy is a lightweight Docker service that acts as an intermediary between AI Agents and LLM providers (such as OpenAI and Anthropic). It captures and forwards agent interactions to the Invariant Explorer, enabling seamless debugging, visualization and exploration of traces.

Invariant Proxy Diagram

Why Use Invariant Proxy?

  • Intercept AI interactions for better debugging and analysis.
  • Seamlessly forward API requests to OpenAI, Anthropic, and other LLM providers (supports streaming responses too).
  • Automatically store and organize traces in the Invariant Explorer.

Getting Started

To integrate the Proxy with your AI agent, youll need to modify how your client interacts with LLM providers.

  1. Setup an Invariant API Key
    Follow the instructions here to obtain an API key.

🔹 OpenAI Integration

  1. To setup an OpenAI API key follow the steps here.

  2. Modify OpenAI Client Setup
    Instead of connecting directly to OpenAI, configure your OpenAI client to use the proxy.

    from httpx import Client
    from openai import OpenAI
    
    client = OpenAI(
        http_client=Client(
            headers={
                "Invariant-Authorization": "Bearer your-invariant-api-key"
            },
        ),
        base_url="https://explorer.invariantlabs.ai/api/v1/proxy/{add-your-dataset-name-here}/openai",
    )
    # If a dataset with the given name already doesn't exist in Invariant Explorer, this will create the dataset
    # before adding the traces to it.
    # Make API requests to OpenAI using the client as usual.
    
    

🔹 Anthropic Integration

  1. To setup an Anthropic API key follow the steps here.

  2. Modify Anthropic Client Setup
    Instead of connecting directly to Anthropic, configure your Anthropic client to use the proxy.

    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/proxy/{add-your-dataset-name-here}/anthropic",
    )
    
    # If a dataset with the given name already doesn't exist in Invariant Explorer, this will create the dataset
    # before adding the traces to it.
    # Make API requests to Anthropic using the client as usual.
    
    

Run

./run.sh up

Run tests

./run.sh tests
Languages
Python 98.1%
Shell 1.9%