Language integration

Twin Browser + Python

Python is where most agent code lives — LangChain, LlamaIndex, CrewAI, AutoGen, Pydantic AI and the OpenAI and Anthropic SDKs are all Python-first. Anything you can express as a function call, an agent can be given as a tool.

Language4-step setupBearer key auth

How Twin plugs into Python

There is no Twin Python package to install: `requests` or `httpx` and a Bearer key are the whole integration. One small helper — the one below — is what every Python framework entry on this site imports. Wrap it in your framework’s tool decorator and the model can drive a real browser; call it directly from a script or a cron job and you have a headless worker with a credential vault and a human-in-the-loop handoff behind it.

Twin is the browser execution layer your stack calls. The first run cold-compiles a skill via skill compilation; every similar request after that is matched from the cache and replayed deterministically, so your marginal cost per run trends toward zero rather than climbing with usage.

app.example.com
  1. Receive goal from Pythondone
  2. Compile DOM → token-efficient indexed statedone
  3. Match the semantic dispatch cacherunning
  4. Replay compiled skill — 0 LLM callsqueued

Wire it up

Drop Twin into Python.

Copy, paste, and swap in your Bearer key. The first run compiles a skill; repeats match the semantic dispatch cache and replay deterministically.

twin.py — the whole integrationpython
import os, requests

TWIN = "https://twin-browser.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['TWIN_API_KEY']}"}

def twin_run(url: str, prompt: str, success: dict) -> dict:
    """Run a browser goal on an authorized target and return the result."""
    r = requests.post(
        f"{TWIN}/run",
        headers=HEADERS,
        json={"url": url, "prompt": prompt, "success": success},
        timeout=300,
    )
    r.raise_for_status()
    return r.json()

Base URL https://twin-browser.com/api/v1 · auth Authorization: Bearer ab_live_… · over MCP the same engine is run_goal, compile_skill and run_skill the full tool table.

  1. Install a HTTP client

    pip install requests (or httpx). There is no Twin SDK package — the API is plain HTTPS.

  2. Export your key

    Set TWIN_API_KEY to a key from the dashboard; it starts with ab_live_.

  3. Copy the helper

    Paste the twin_run helper below. It posts { url, prompt, success } to /api/v1/run and returns the parsed result.

  4. Wrap it as a tool

    Hand the function to whichever framework you use, or call it directly from a script.

FAQ

Python on Twin — common questions

Is there a Twin Browser Python SDK on PyPI?
No. Twin does not publish a Python package, and any page claiming a `pip install` for one is wrong. The REST API is the supported Python path, and the helper on this page is the complete wiring.
What goes in the success condition?
An object whose kind is one of statusText, urlIncludes, textVisible, extracted, allOf or anyOf. It is how the engine knows the run finished, and it is validated at the edge, so a malformed one returns a clean 400 instead of consuming credits.

Wire up Python in minutes.

Free to start. Usage-based credits from $29/mo — each call billed the higher of its flat action price or its metered cost.