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.
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.
What you get through Python
Every integration is a thin wrapper over the same execution layer, so the cache, the replay, and the corpus apply no matter how you call in.
Semantic dispatch cache
A re-phrased goal fuzzy-matches an already-compiled skill, so most calls never touch the LLM.
Deterministic replay
A compiled skill replays the exact action path with zero LLM calls — fast, repeatable, cheap.
Cross-tenant skill corpus
A skill compiled once can be safely reused across tenants, so the hit rate climbs as the network runs.
One Bearer key
Auth, usage-based billing, and an audit log run on every call — the same key works from every integration.
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.
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.
Install a HTTP client
pip install requests (or httpx). There is no Twin SDK package — the API is plain HTTPS.
Export your key
Set TWIN_API_KEY to a key from the dashboard; it starts with ab_live_.
Copy the helper
Paste the twin_run helper below. It posts { url, prompt, success } to /api/v1/run and returns the parsed result.
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?
What goes in the success condition?
Related
More ways to connect Twin
- Agent framework
LangChain
LangChain is a Python and JavaScript framework for building LLM applications. Its agent loop lets a model pick a tool, observe the result, and decide the next action — which makes browser access a natural tool to add.
- Agent framework
CrewAI
CrewAI is a Python framework for multi-agent “crews” — role-playing agents that collaborate on tasks. Tools are shared across the crew, and `@tool` from `crewai.tools` turns a function into one, using the docstring as the description the agents read.
- API
REST API
Twin’s REST API is the universal integration path: HTTPS endpoints under `/api/v1/*`, authenticated with a Bearer key. Any language that can make an HTTP request can drive the browser execution layer — no SDK required, and none is published.
Integrations
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.