Skip to content

Browser Use Integration

Use Gateway with browser-use

Browser Use is a simple library to connect your AI agents with the browser.

You can easily modify the Browser Use setup to use the Invariant Gateway.

Getting the Invariant API Key

Visit the Explorer Documentation to learn how to obtain your own API key.

Adjust the API Key Format

browser-use does not support custom headers, so you cannot pass the Invariant API Key via the Invariant-Authorization header as usual.

However, you can still use Gateway by relying on its support for secret key concatenation.

Instead of setting your LLM Provider's API Key normally, modify the environment variable as follows:

export OPENAI_API_KEY={your-openai-api-key};invariant-auth={your-invariant-api-key}
export ANTHROPIC_API_KEY={your-anthropic-api-key};invariant-auth={your-invariant-api-key}

Code

You can now use the Invariant Gateway with your browser-use client as follows:

import asyncio

from browser_use import Agent
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI

load_dotenv()


async def main():
    agent = Agent(
        task="Go to Reddit, search for 'browser-use', click on the first post and return the first comment.",
        llm=ChatOpenAI(
            model="gpt-4o",
            base_url="https://explorer.invariantlabs.ai/api/v1/gateway/{add-your-dataset-name-here}/openai",
        ),
    )
    result = await agent.run()
    print(result)


asyncio.run(main())

Note: Do not include the curly braces {}.

The Invariant Gateway extracts the invariant-auth field from the API key and correctly forwards it to Invariant Explorer while sending the actual API key to OpenAI or Anthropic.

This will automatically trace your agent interactions in Invariant Explorer.

Explore Other Integrations