> ## Documentation Index
> Fetch the complete documentation index at: https://docs.browserbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MPP quickstart

> Pay for a browser session with Link CLI, then connect with Stagehand, Playwright, or Puppeteer.

Use [`link-cli mpp pay`](https://docs.stripe.com/agentic-commerce/agents/link-agent-wallet/machine-payments) to request a browser session, approve the payment in Link, and connect with Stagehand, Playwright, or Puppeteer. You don't need a Browserbase account or API key.

## Connect your Link account

Install Link CLI with [Node.js](https://nodejs.org/):

```bash theme={null}
npm install -g @stripe/link-cli
link-cli auth status
```

If Link isn't connected, start the login flow:

```bash theme={null}
link-cli auth login \
  --client-name "Browserbase agent" \
  --scope "userinfo:read payment_methods.agentic" \
  --interval 5 \
  --timeout 300
```

Open the verification URL, sign in, and approve the connection. Wait for authentication to finish before requesting a payment. Add a payment method in [Link](https://app.link.com) if needed.

If an existing connection doesn't include the `payment_methods.agentic` scope, use `link-cli auth upgrade` with the same options to add it.

## Inspect the payment challenge

Make an unauthenticated request to see the price before paying:

```bash cURL theme={null}
curl -i https://mpp.browserbase.com/browser/session/create \
  -H 'Content-Type: application/json' \
  -d '{"estimatedMinutes": 250}'
```

Browserbase returns `402 Payment Required` with payment challenges in the `WWW-Authenticate` header. Link CLI uses the challenge with `method="stripe"`, which specifies the merchant, amount, and currency. This request doesn't create a session or make a payment.

This example requests **250 minutes for 0.50 USD**, the minimum purchase. Increase `estimatedMinutes` to buy more time.

## Pay with Link

Run `link-cli mpp pay` with the same session request:

```bash theme={null}
link-cli mpp pay https://mpp.browserbase.com/browser/session/create \
  --method POST \
  --header 'Content-Type: application/json' \
  --data '{"estimatedMinutes": 250}' \
  --context "Pay for 250 minutes of Browserbase browser access so my agent can complete the web browsing task I requested, using the amount quoted by Browserbase."
```

The CLI reads the amount and currency from the payment challenge and creates the spend request for you. The `--context` explains the purchase in Link's approval screen and must be at least 100 characters.

Open the approval URL returned by the CLI and review the amount before approving. Follow the CLI's continuation instructions to finish the request. After approval, Link CLI retrieves a one-time Shared Payment Token and sends it to Browserbase in an MPP payment credential.

When calling the CLI from an agent, invoke the returned `_next.pay_argv` command and argument array directly. Set its JSON header to `Content-Type: application/json`, preserving capitalization, and keep the original `--approved-challenge`, method, and body. See [Stripe's Link CLI guide](https://docs.stripe.com/agentic-commerce/agents/link-agent-wallet/machine-payments) for details.

After a successful payment, Browserbase returns session details including:

```json theme={null}
{
  "sessionId": "<session-id>",
  "connectUrl": "wss://connect.browserbase.com/...",
  "paidMinutes": 250,
  "expiresAt": "<expiration-timestamp>",
  "pricing": {
    "ratePerHour": 0.12,
    "amountPaid": 0.5,
    "currency": "USD"
  }
}
```

Keep the `sessionId` for status checks and the `connectUrl` for browser access. Treat the connection URL as a credential: anyone with it can connect while the session is active.

## Connect to the session

Set `BROWSERBASE_CONNECT_URL` in your environment to the `connectUrl` from the response. Choose a browser library, install it, and save its example as `browser.mjs`.

<Tabs>
  <Tab title="Stagehand">
    [Stagehand](https://docs.stagehand.dev/v3/first-steps/introduction) runs in your Node.js process and connects to the paid browser session over CDP.

    ```bash theme={null}
    npm install @browserbasehq/stagehand@3
    ```

    ```javascript Node.js theme={null}
    import { Stagehand } from "@browserbasehq/stagehand";

    const stagehand = new Stagehand({
      env: "LOCAL",
      localBrowserLaunchOptions: {
        cdpUrl: process.env.BROWSERBASE_CONNECT_URL,
      },
    });

    await stagehand.init();

    try {
      const page =
        stagehand.context.pages()[0] ?? (await stagehand.context.newPage());
      await page.goto("https://example.com");
      console.log(await page.title());
    } finally {
      await stagehand.close();
    }
    ```
  </Tab>

  <Tab title="Playwright">
    ```bash theme={null}
    npm install playwright-core
    ```

    ```javascript Node.js theme={null}
    import { chromium } from "playwright-core";

    const browser = await chromium.connectOverCDP(
      process.env.BROWSERBASE_CONNECT_URL,
    );

    try {
      const context = browser.contexts()[0];
      const page = context.pages()[0] ?? (await context.newPage());
      await page.goto("https://example.com");
      console.log(await page.title());
    } finally {
      await browser.close();
    }
    ```
  </Tab>

  <Tab title="Puppeteer">
    ```bash theme={null}
    npm install puppeteer-core
    ```

    ```javascript Node.js theme={null}
    import puppeteer from "puppeteer-core";

    const browser = await puppeteer.connect({
      browserWSEndpoint: process.env.BROWSERBASE_CONNECT_URL,
    });

    try {
      const pages = await browser.pages();
      const page = pages[0] ?? (await browser.newPage());
      await page.goto("https://example.com");
      console.log(await page.title());
    } finally {
      await browser.disconnect();
    }
    ```
  </Tab>
</Tabs>

Run the example:

```bash theme={null}
node browser.mjs
```

## Expected output

The script prints `Example Domain`.

## Manage the session

Set `SESSION_ID` to the returned `sessionId`. You can check the remaining browser time without another payment:

```bash cURL theme={null}
curl "https://mpp.browserbase.com/browser/session/$SESSION_ID/status"
```

## Cleanup

When you're finished, terminate the session:

```bash cURL theme={null}
curl -X DELETE "https://mpp.browserbase.com/browser/session/$SESSION_ID"
```

## Further reading

See the [Link CLI documentation](https://docs.stripe.com/agentic-commerce/agents/link-agent-wallet/machine-payments) for approval and Shared Payment Tokens.

<CardGroup cols={2}>
  <Card title="MPP overview" icon="coins" href="/integrations/mpp/introduction">
    Review pricing, prerequisites, and how the payment flow works.
  </Card>

  <Card title="x402 quickstart" icon="rocket" href="/integrations/x402/quickstart">
    Create browser sessions using x402 payments.
  </Card>
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.