Language integration
Twin Browser + Node.js & TypeScript
Node is the other half of the agent ecosystem — the Vercel AI SDK, LangChain.js, and the OpenAI and Anthropic TypeScript SDKs all run here, and it is where most production API routes and background workers live.
How Twin plugs into Node.js & TypeScript
Global `fetch` and a Bearer key are the whole integration; there is no `@twin-browser/*` package to install and none is published. The function below is what the Vercel AI SDK entry wraps in `tool()`, what a Next.js route handler calls, and what a queue worker runs on a schedule — the same `/api/v1/run` endpoint every other path on this page reaches.
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 Node.js & TypeScriptdone
- Compile DOM → token-efficient indexed statedone
- Match the semantic dispatch cacherunning
- Replay compiled skill — 0 LLM callsqueued
What you get through Node.js & TypeScript
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 Node.js & TypeScript.
Copy, paste, and swap in your Bearer key. The first run compiles a skill; repeats match the semantic dispatch cache and replay deterministically.
const TWIN = 'https://twin-browser.com/api/v1';
type Success =
| { kind: 'statusText'; match: string }
| { kind: 'urlIncludes'; value: string }
| { kind: 'textVisible'; value: string }
| { kind: 'extracted' };
export async function twinRun(url: string, prompt: string, success: Success) {
const res = await fetch(`${TWIN}/run`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.TWIN_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ url, prompt, success }),
});
if (!res.ok) throw new Error(`Twin ${res.status}: ${await res.text()}`);
return res.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.
Set your key
Put TWIN_API_KEY (an ab_live_ key from the dashboard) in your environment — never in client-side code.
Copy the helper
Paste the twinRun function below. Node 18+ has global fetch, so there is nothing to install.
Call it server-side
Use it from a route handler, a worker or a script. The key is a server secret; a browser must never see it.
Compile the repeats
Once a goal succeeds reliably, compile it and call /api/v1/skills/{name}/run for a deterministic replay.
FAQ
Node.js & TypeScript on Twin — common questions
Is there an @twin-browser/sdk package?
Can I call Twin from the browser?
Related
More ways to connect Twin
Vercel AI SDK
The Vercel AI SDK is a TypeScript toolkit for building AI applications — a unified interface across model providers, streaming, structured output and tool calling. A tool is defined with the `tool()` helper: a description, an `inputSchema`, and an `execute` function.
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.
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 Node.js & TypeScript 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.