Browser session (multi-step)
POST /api/browser-sessionA multi-step headless Chromium session: open it with a goto, then send one step per call...
Details
A multi-step headless Chromium session: open it with a goto, then send one step per call (goto, click by CSS selector or text, type (optional Enter), wait for a selector, extract text, links or a table, screenshot). Each call is one paid step and answers its result and the page's url, title, status and text preview. The first call (no sessionId) returns session.id. Identity-bound: a session belongs to the wallet whose signed EVM x402 authorization opened it; another payer's step reads as unknown. Limits: 10 minutes per session, 2 minutes idle, 60 steps, 2 open sessions per wallet (another closes its least recently used idle one), one step at a time. "close": true ends the session after its step. Every navigation, redirect, frame and subresource passes render's public-address checks (http(s) only); downloads and pop-ups are refused. It never types into fields marked or recognized as a password, a one-time code or a payment card (by type, autocomplete, name, id, label, aria-label or placeholder), and never echoes or logs typed text. Each main-frame navigation checks the site's robots.txt first. It does not solve CAPTCHAs or evade bot detection: a site that blocks automated browsers stays blocked. A missing element answers 422 and keeps the session open; a full server answers 503 with Retry-After; neither is charged. Page content is untrusted (untrustedContent: true). Deterministic code, no model. Body: {"action":"goto","url":"https://…"}, then {"sessionId":"bs_…","action":"click","selector":"a"}.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
sessionId | string | no | session.id from the call that opened the session; omit to open a new one (the first step must be goto) |
action | string (one of: goto, click, type, wait, extract, screenshot) | yes | The step: goto, click, type, wait, extract or screenshot One of goto, click, type, wait, extract, screenshot. |
url | string | no | goto: a public http(s) URL Up to 2048 characters. The example sends https://agent402.tools/. |
selector | string | no | click, type, wait: a CSS selector (first match). extract: optional scope (or the table to read) |
text | string | no | click: visible text to click (instead of selector). type: the text to put in the field (up to 2000 characters, never echoed) |
submit | boolean | no | type: press Enter after typing (default false) |
timeoutMs | integer | no | wait: how long to wait for the selector, 100 to 15000 (default 5000) |
what | string (one of: text, links, table) | no | extract: what to read (default text) One of text, links, table. |
fullPage | boolean | no | screenshot: the whole page up to 5000 px tall (default: the viewport) |
close | boolean | no | End the session after this step (default false) The example sends true. |
Example request
curl -i -X POST https://agent402.tools/api/browser-session \
-H "Content-Type: application/json" \
-d '{"action":"goto","url":"https://agent402.tools/","close":true}'Watch a call get paid
POST /api/browser-session$0.005 USDCPAYMENT-SIGNATUREon 11 chains200 OKAgent402-ReceiptEd25519Example response
{
"session": {
"id": "bs_5mYb0p1Qm6X1R9tq3kq8m3vX0a8b3Kq2",
"opened": true,
"stepsUsed": 1,
"stepsLeft": 59,
"expiresAt": "2026-11-29T12:10:00.000Z",
"idleTimeoutSeconds": 120,
"closed": true,
"closedReason": "closed"
},
"step": {
"action": "goto",
"ok": true,
"status": 200
},
"page": {
"url": "https://agent402.tools/",
"title": "Page title",
"status": 200,
"textPreview": "…",
"textChars": 4000
},
"untrustedContent": true
}| Field | Type | Always present | In the example |
|---|---|---|---|
session | object | yes | 8 fields: id, opened, stepsUsed, stepsLeft, expiresAt and 3 more |
step | object | yes | 3 fields: action, ok, status |
page | object | yes | 5 fields: url, title, status, textPreview, textChars |
untrustedContent | boolean | yes | true |
From an MCP client
catalog.call {
"slug": "browser-session",
"params": {
"action": "goto",
"url": "https://agent402.tools/",
"close": true
}
}Hosted connector (https://agent402.tools/mcp): paid in the call. Stdio package (npx -y agent402-mcp@0.18.0): pays from a wallet.
Errors and behavior
- Pay $0.005 per call over x402 with USDC on an EVM chain. Wallet-only: this tool reaches the network or stored state, so it has no proof-of-work tier.
- Required:
action; a rejected input answers 4xx witherror,tool,expected,requiredandexample. - On this route, a call ending in any status of 400 or above is not charged over x402 or MPP.
- Identity-bound: results are keyed to the paying wallet, so only EVM x402 payments are accepted; credits keys and Tempo are refused.
- A bodyless
GETorHEADreturns the same 402 quote. - An
Idempotency-Keyreplays the first 200 uncharged (an answer larger than 1 MB is not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.005" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/browser-session", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"action": "goto",
"url": "https://agent402.tools/",
"close": true
}),
});Get a wallet or run npx -y agent402-mcp@0.18.0 wallet new.
The quote (Python)
import base64, json, urllib.error, urllib.request
req = urllib.request.Request("https://agent402.tools/api/browser-session", method="POST", data="{\"action\":\"goto\",\"url\":\"https://agent402.tools/\",\"close\":true}".encode(), headers={"Content-Type": "application/json"})
try:
urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
quote = json.loads(base64.b64decode(e.headers["PAYMENT-REQUIRED"]))
print(e.code, [(a["network"], a["amount"]) for a in quote["accepts"]]) # the price, per chain, in base units