Skip to main content
Use web.agent() when a browser-agent task belongs inside your application.

Prerequisites

  • Node.js 20 or newer, plus npm or another Node package manager.
  • A Webcompute API key exported as WEBCOMPUTE_API_KEY. The TypeScript SDK reads the key from this environment variable or from new Web({ apiKey }).
  • A model-provider key for the route you choose. This page uses OpenRouter, so export OPENROUTER_API_KEY.
  • A browser-agent task you have already proven with the CLI quickstart, so the SDK version starts from a working prompt and domain boundary.

Install the SDK

npm install https://install.webcompute.dev/sdk/latest.tgz
Version metadata is published at https://install.webcompute.dev/sdk/latest.json for pinned installs. Set your Webcompute API key:
export WEBCOMPUTE_API_KEY=wc_key_your_key_here
export OPENROUTER_API_KEY=your_provider_key
If you used web model setup in the CLI, copy the same route, model, and credential env-var name into SDK code. SDK web.agent() requires explicit model config.

Run an agent workflow

import { Web } from "@webcompute/sdk";

const web = new Web();

const agent = web.agent({
  model: {
    route: "openrouter",
    model: "openai/gpt-5.4-mini",
    apiKeyEnv: "OPENROUTER_API_KEY",
  },
  browser: {
    create: { recording: true },
    policy: { allowedDomains: ["sec.gov"] },
  },
  approval: "ask",
});

const result = await agent.run({
  startUrl: "https://www.sec.gov/edgar/search/",
  goal:
    "Find Apple's latest 10-Q filings. Return filing date, accession number, filing URL, and a one-sentence summary.",
});

if (result.status !== "completed") {
  throw new Error(result.error?.message ?? `Agent run ended with ${result.status}`);
}

console.log(result.text);
console.log(result.browserId);
The agent creates a managed browser, stays inside sec.gov, records the run, and returns a final result. One-shot agent runs close browsers they create when the run completes. Use long-running tasks or an explicit browser session when your application needs continuity or post-run live inspection. Use the SDK reference when you need the full surface: agent, browser, resources, quick actions, policy, and proxy.

Read the result

console.log(result.status);
console.log(result.text);
console.log(result.steps.length);
console.log(result.artifacts);
Use result.output when you provide an output schema. Use result.steps and result.artifacts when you need evidence for logs, review, or debugging.
Signed Debug UI and CDP URLs are bearer capabilities. Do not log them or expose them to untrusted users.

Next steps