Skip to main content

Quick Start

1

Install Dependencies

npm install viem x402
2

Create a Session

Run the following with your wallet’s private key (requires USDC on Base):
PRIVATE_KEY=0x... npx tsx scripts/test-with-wallet.ts

API Reference

Create Session

Creates a new browser session with prepaid time.
POST /browser/session/create
Request Body:
{
  "estimatedMinutes": 30
}
When you first make a request, you’ll receive a 402 Payment Required response with payment details:
{
  "x402Version": 1,
  "accepts": [{
    "scheme": "exact",
    "network": "base",
    "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "maxAmountRequired": "500000",
    "payTo": "0x...",
    "resource": "https://x402.browserbase.com/browser/session/create"
  }]
}

Get Session Status

Check the status of an active session.
GET /browser/session/:id/status
Response:
{
  "sessionId": "abc-123",
  "status": "active",
  "usage": {
    "minutesPaid": 30,
    "minutesUsed": 5,
    "minutesRemaining": 25
  },
  "expiresAt": "2025-12-03T18:00:00Z"
}

Extend Session

Add more time to an active session.
POST /browser/session/:id/extend
Request Body:
{
  "additionalMinutes": 15
}
Extending a session requires another x402 payment for the additional time.

Terminate Session

End a session early. Unused time may be eligible for refund.
POST /browser/session/:id/terminate
Response:
{
  "sessionId": "abc-123",
  "finalStatus": "terminated",
  "usage": {
    "minutesPaid": 30,
    "minutesUsed": 10
  },
  "refund": {
    "eligible": true,
    "amount": 0.33,
    "currency": "USDC"
  }
}

Making x402 Payments

Using Your Session

Once you have a connectUrl, connect with Playwright or Puppeteer:
import { chromium } from "playwright";

const browser = await chromium.connectOverCDP(session.connectUrl);
const page = browser.contexts()[0].pages()[0];

await page.goto("https://example.com");
await page.screenshot({ path: "screenshot.png" });

await browser.close();

Further Reading