> ## 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.

# Stagehand

> Build browser agents with Stagehand + Browserbase

There's a new way to automate the web: by prompting.

Stagehand is the SDK that gives agents the tools they need to navigate the web. Build with self-healing browser primitives that adapt when websites change.

Use any major model provider. 22k GitHub stars, 700k+ weekly downloads. Get started in 5 minutes.

<Note>
  This quickstart uses [Model Gateway](/platform/model-gateway/overview). LLM requests for Stagehand route through your Browserbase API key, so you don't need a separate model provider account. You can also [bring your own API key](https://docs.stagehand.dev/v4/configuration/models) if you prefer.
</Note>

<CardGroup cols={3}>
  <Card title="Discord" icon="discord" href="https://discord.gg/stagehand">
    Community support
  </Card>

  <Card title="Docs" icon="book" href="https://docs.stagehand.dev">
    Full documentation
  </Card>

  <Card title="Templates" icon="rocket" href="https://browserbase.com/templates">
    Ready-to-use examples
  </Card>
</CardGroup>

## Quickstart

<Steps>
  <Step title="Get your API key">
    Your API key is displayed in the [Dashboard Navigation row](https://www.browserbase.com/sessions). The API key is all you need to get started. The project is inferred from your API key.

    <Frame>
      <img src="https://mintcdn.com/browserbase/giE_cpy18f2mWHqr/images/quickstart/api_key.png?fit=max&auto=format&n=giE_cpy18f2mWHqr&q=85&s=4ac94a8f69cec20bd17b2a8788169062" width="3410" height="1864" data-path="images/quickstart/api_key.png" />
    </Frame>
  </Step>

  <Step title="Set environment variables">
    ```bash theme={null}
    export BROWSERBASE_API_KEY="your-api-key"
    ```
  </Step>

  <Step title="Install and run">
    <Tabs>
      <Tab title="Node.js">
        <CodeGroup>
          ```bash pnpm theme={null}
          pnpm add @browserbasehq/stagehand zod
          npm pkg set type=module
          ```

          ```bash npm theme={null}
          npm install @browserbasehq/stagehand zod
          npm pkg set type=module
          ```
        </CodeGroup>

        ```typescript Node.js theme={null}
        import { browserbase, Stagehand } from "@browserbasehq/stagehand";
        import { z } from "zod/v4";

        const browser = await browserbase.launch({
          apiKey: process.env.BROWSERBASE_API_KEY,
        });

        try {
          const stagehand = await Stagehand.create({ browser });

          try {
            const [page] = await browser.context.pages();
            await page.goto("https://news.ycombinator.com");

            await stagehand.act("Click the comments link for the top story");

            const result = await stagehand.extract(
              "Extract the title and points of the top story",
              z.object({
                title: z.string(),
                points: z.string(),
              }),
            );
            console.log(result.data);
          } finally {
            await stagehand.close();
          }
        } finally {
          await browser.close();
        }
        ```

        Save as `script.ts`, then run:

        <CodeGroup>
          ```bash pnpm theme={null}
          pnpm dlx tsx script.ts
          ```

          ```bash npm theme={null}
          npx tsx script.ts
          ```
        </CodeGroup>
      </Tab>

      <Tab title="Python">
        ```bash theme={null}
        uv init
        uv add stagehand pydantic
        ```

        ```python theme={null}
        import asyncio
        import os

        from pydantic import BaseModel
        from stagehand import Stagehand, browserbase


        class Story(BaseModel):
            title: str
            points: str


        async def main() -> None:
            browser = await browserbase.launch(
                api_key=os.environ["BROWSERBASE_API_KEY"],
            )

            try:
                stagehand = await Stagehand.create(browser=browser)

                try:
                    page = (await browser.context.pages())[0]
                    await page.goto("https://news.ycombinator.com")

                    await stagehand.act("Click the comments link for the top story")

                    result = await stagehand.extract(
                        "Extract the title and points of the top story",
                        Story,
                    )
                    print(result.data)
                finally:
                    await stagehand.close()
            finally:
                await browser.close()


        asyncio.run(main())
        ```

        Save as `script.py`, then run:

        ```bash theme={null}
        uv run script.py
        ```
      </Tab>

      <Tab title="Go">
        Follow the [Stagehand v4 quickstart →](https://docs.stagehand.dev/v4/first-steps/quickstart)
      </Tab>
    </Tabs>
  </Step>

  <Step title="Debug in Session Inspector">
    See every AI decision in the **[Stagehand tab](/platform/browser/observability/observability#stagehand)** of your session at `https://browserbase.com/sessions/{session_id}`.
  </Step>
</Steps>

## Next steps

<CardGroup cols={2}>
  <Card title="Stagehand docs" icon="graduation-cap" href="https://docs.stagehand.dev">
    Learn about Stagehand primitives, models, and Browserbase configurations
  </Card>

  <Card title="npx create-browser-app" icon="terminal" href="https://github.com/browserbase/create-browser-app">
    Scaffold a Stagehand project in one command. TypeScript, zero-config.
  </Card>
</CardGroup>
