LLM provider integration
Twin Browser + Anthropic (Claude tool use)
Claude’s Messages API supports tool use: you pass a `tools` array where each tool has a `name`, a `description` and an `input_schema`. When Claude decides to use one, the response comes back with `stop_reason: "tool_use"`, you execute it, and you return a `tool_result` block in the next message.
How Twin plugs into Anthropic (Claude tool use)
Define one tool whose input schema is a URL and a prompt, and Claude gains a real browser. Two things make this pairing worth the page. First, Twin’s own planner runs server-side, so the browser loop does not consume your Claude context — you get one structured result back, not a hundred DOM snapshots. Second, if you are using Claude through an MCP client rather than the raw API, you do not need this tool definition at all: register `twin-browser-mcp` and all 31 tools appear.
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.
- Receive goal from Anthropic (Claude tool use)done
- Compile DOM → token-efficient indexed statedone
- Match the semantic dispatch cacherunning
- Replay compiled skill — 0 LLM callsqueued
What you get through Anthropic (Claude tool use)
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 Anthropic (Claude tool use).
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, anthropic
client = anthropic.Anthropic()
TWIN_TOOL = {
"name": "twin_run",
"description": "Perform a task in a real browser on an authorized URL, "
"including pages that require signing in.",
"input_schema": {
"type": "object",
"properties": {
"url": {"type": "string", "description": "The page to start from"},
"prompt": {"type": "string", "description": "What to do there"},
},
"required": ["url", "prompt"],
},
}
def twin_run(url, prompt):
r = requests.post(
"https://twin-browser.com/api/v1/run",
headers={"Authorization": f"Bearer {os.environ['TWIN_API_KEY']}"},
json={"url": url, "prompt": prompt, "success": {"kind": "extracted"}},
timeout=300,
)
return r.json()
msg = client.messages.create(
model="claude-sonnet-5",
max_tokens=1024,
tools=[TWIN_TOOL],
messages=[{"role": "user", "content": "Download last month's invoice from the billing portal."}],
)
# if msg.stop_reason == "tool_use": run twin_run(**block.input) and reply
# with a {"type": "tool_result", "tool_use_id": block.id, "content": ...} block.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 the SDK
pip install anthropic and set ANTHROPIC_API_KEY.
Declare the tool
Add a twin_run tool with an input_schema of url and prompt to the tools array.
Execute on tool_use
When stop_reason is tool_use, POST { url, prompt, success } to /api/v1/run.
Return a tool_result
Send the structured result back as a tool_result content block in the next message.
FAQ
Anthropic (Claude tool use) on Twin — common questions
Should I use tool use or the MCP server with Claude?
Does driving a browser fill up Claude’s context?
Related
More ways to connect Twin
Claude Desktop
Claude Desktop is Anthropic’s desktop app for Claude, and it can launch local MCP servers listed in `claude_desktop_config.json`. Registered tools become available to Claude in the conversation.
Claude Code
Claude Code is Anthropic’s agentic coding tool for the terminal, and it supports MCP servers. Registered tools become available to the agent so it can take real actions — including browser automation — as part of a coding task.
MCP (Model Context Protocol)
MCP is an open protocol that lets an LLM application discover and call external tools over a standard interface. An MCP client — Claude Desktop, Claude Code, Cursor, Windsurf, VS Code, Cline — launches or connects to an MCP server, lists its tools, and invokes them on the model’s behalf, with no bespoke glue per app.
Wire up Anthropic (Claude tool use) 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.