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.

LLM provider4-step setupBearer key auth

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.

app.example.com
  1. Receive goal from Anthropic (Claude tool use)done
  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 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.

Claude tool use → Twin RESTpython
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.

  1. Install the SDK

    pip install anthropic and set ANTHROPIC_API_KEY.

  2. Declare the tool

    Add a twin_run tool with an input_schema of url and prompt to the tools array.

  3. Execute on tool_use

    When stop_reason is tool_use, POST { url, prompt, success } to /api/v1/run.

  4. 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?
Use MCP whenever the client supports it — Claude Desktop, Claude Code, Cursor and Cline all do — because the schemas come from the server and stay correct. Use raw tool use when you are calling the Messages API directly from your own backend.
Does driving a browser fill up Claude’s context?
Not through Twin. The planning loop, the DOM serialization and the retries happen server-side; your conversation sees one structured result. That is a different cost profile from a computer-use loop that streams screenshots back into the context window.

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.