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

# Extract data from the page

> Extracts structured data from the current page using AI-powered analysis.



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/stagehand/openapi.documented.yml post /v1/sessions/{id}/extract
openapi: 3.1.0
info:
  title: Stagehand API
  version: 3.1.0
  description: >-
    Stagehand SDK for AI browser automation [ALPHA]. This API allows clients to

    execute browser automation tasks remotely on the Browserbase cloud.

    All endpoints except /sessions/start require an active session ID.

    Responses are streamed using Server-Sent Events (SSE) when the

    `x-stream-response: true` header is provided.


    This SDK is currently ALPHA software and is not production ready!

    Please try it and give us your feedback, stay tuned for upcoming release
    announcements!
  contact:
    name: Browserbase
    url: https://browserbase.com
servers:
  - url: https://api.stagehand.browserbase.com
security:
  - BrowserbaseApiKey: []
    BrowserbaseProjectId: []
paths:
  /v1/sessions/{id}/extract:
    post:
      summary: Extract data from the page
      description: >-
        Extracts structured data from the current page using AI-powered
        analysis.
      operationId: SessionExtract
      parameters:
        - schema:
            description: Unique session identifier
            example: c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123
            type: string
          in: path
          name: id
          required: true
          description: Unique session identifier
        - schema:
            description: Whether to stream the response via SSE
            example: 'true'
            type: string
            enum:
              - 'true'
              - 'false'
          in: header
          name: x-stream-response
          description: Whether to stream the response via SSE
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExtractRequest'
        required: true
      responses:
        '200':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExtractResponse'
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import Stagehand from 'stagehand-sdk';


            const client = new Stagehand({
              browserbaseAPIKey: process.env['BROWSERBASE_API_KEY'], // This is the default and can be omitted
              browserbaseProjectID: process.env['BROWSERBASE_PROJECT_ID'], // This is the default and can be omitted
              modelAPIKey: process.env['MODEL_API_KEY'], // This is the default and can be omitted
            });


            const response = await
            client.sessions.extract('c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123');


            console.log(response.data);
        - lang: Python
          source: |-
            import os
            from stagehand import Stagehand

            client = Stagehand(
                browserbase_api_key=os.environ.get("BROWSERBASE_API_KEY"),  # This is the default and can be omitted
                browserbase_project_id=os.environ.get("BROWSERBASE_PROJECT_ID"),  # This is the default and can be omitted
                model_api_key=os.environ.get("MODEL_API_KEY"),  # This is the default and can be omitted
            )
            for session in client.sessions.extract(
                id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
            ):
              print(session)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/browserbase/stagehand-go\"\n\t\"github.com/browserbase/stagehand-go/option\"\n)\n\nfunc main() {\n\tclient := stagehand.NewClient(\n\t\toption.WithBrowserbaseAPIKey(\"My Browserbase API Key\"),\n\t\toption.WithBrowserbaseProjectID(\"My Browserbase Project ID\"),\n\t\toption.WithModelAPIKey(\"My Model API Key\"),\n\t)\n\tresponse, err := client.Sessions.Extract(\n\t\tcontext.TODO(),\n\t\t\"c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123\",\n\t\tstagehand.SessionExtractParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.Data)\n}\n"
        - lang: Java
          source: |-
            package com.browserbase.api.example;

            import com.browserbase.api.client.StagehandClient;
            import com.browserbase.api.client.okhttp.StagehandOkHttpClient;
            import com.browserbase.api.models.sessions.SessionExtractParams;
            import com.browserbase.api.models.sessions.SessionExtractResponse;

            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    StagehandClient client = StagehandOkHttpClient.fromEnv();

                    SessionExtractResponse response = client.sessions().extract("c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123");
                }
            }
        - lang: Kotlin
          source: |-
            package com.browserbase.api.example

            import com.browserbase.api.client.StagehandClient
            import com.browserbase.api.client.okhttp.StagehandOkHttpClient
            import com.browserbase.api.models.sessions.SessionExtractParams
            import com.browserbase.api.models.sessions.SessionExtractResponse

            fun main() {
                val client: StagehandClient = StagehandOkHttpClient.fromEnv()

                val response: SessionExtractResponse = client.sessions().extract("c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123")
            }
        - lang: Ruby
          source: >-
            require "stagehand"


            stagehand = Stagehand::Client.new(
              browserbase_api_key: "My Browserbase API Key",
              browserbase_project_id: "My Browserbase Project ID",
              model_api_key: "My Model API Key"
            )


            response =
            stagehand.sessions.extract("c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123")


            puts(response)
        - lang: PHP
          source: |-
            <?php

            require_once dirname(__DIR__) . '/vendor/autoload.php';

            use Stagehand\Client;
            use Stagehand\Core\Exceptions\APIException;

            $client = new Client(
              browserbaseAPIKey: getenv('BROWSERBASE_API_KEY') ?: 'My Browserbase API Key',
              browserbaseProjectID: getenv(
                'BROWSERBASE_PROJECT_ID'
              ) ?: 'My Browserbase Project ID',
              modelAPIKey: getenv('MODEL_API_KEY') ?: 'My Model API Key',
            );

            try {
              $response = $client->sessions->extract(
                'c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123',
                frameID: 'frameId',
                instruction: 'Extract all product names and prices from the page',
                options: [
                  'ignoreSelectors' => ['nav', '.cookie-banner', '#sidebar-ads'],
                  'model' => [
                    'auth' => [
                      'credentials' => [
                        'clientEmail' => 'client_email',
                        'privateKey' => 'private_key',
                        'authProviderX509CertURL' => 'https://example.com',
                        'authUri' => 'https://example.com',
                        'clientID' => 'client_id',
                        'clientX509CertURL' => 'https://example.com',
                        'privateKeyID' => 'private_key_id',
                        'projectID' => 'project_id',
                        'tokenUri' => 'https://example.com',
                        'type' => 'service_account',
                        'universeDomain' => 'universe_domain',
                      ],
                      'type' => 'googleServiceAccount',
                      'projectID' => 'projectId',
                      'scopes' => 'string',
                      'universeDomain' => 'universeDomain',
                    ],
                    'modelName' => 'openai/gpt-5.4-mini',
                    'provider' => 'vertex',
                    'providerOptions' => [
                      'vertex' => [
                        'location' => 'us-central1',
                        'project' => 'my-gcp-project',
                        'baseURL' => 'https://example.com',
                        'headers' => ['foo' => 'string'],
                      ],
                    ],
                    'apiKey' => 'sk-some-openai-api-key',
                    'baseURL' => 'https://api.openai.com/v1',
                    'headers' => ['foo' => 'string'],
                  ],
                  'screenshot' => false,
                  'selector' => '#main-content',
                  'timeout' => 30000,
                ],
                schema: ['foo' => 'bar'],
                xStreamResponse: 'true',
              );

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: |-
            using System;
            using Stagehand;
            using Stagehand.Models.Sessions;

            StagehandClient client = new();

            SessionExtractParams parameters = new()
            {
                ID = "c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123"
            };

            var response = await client.Sessions.Extract(parameters);

            Console.WriteLine(response);
components:
  schemas:
    ExtractRequest:
      type: object
      properties:
        instruction:
          description: Natural language instruction for what to extract
          example: Extract all product names and prices from the page
          type: string
        schema:
          description: JSON Schema defining the structure of data to extract
          type: object
          propertyNames:
            type: string
          additionalProperties: {}
        options:
          $ref: '#/components/schemas/ExtractOptions'
        frameId:
          description: Target frame ID for the extraction
          anyOf:
            - type: string
            - type: 'null'
        streamResponse:
          description: Whether to stream the response via SSE
          example: true
          type: boolean
    ExtractResponse:
      type: object
      properties:
        success:
          description: Indicates whether the request was successful
          type: boolean
        data:
          $ref: '#/components/schemas/ExtractResultOutput'
      required:
        - success
        - data
      additionalProperties: false
    ExtractOptions:
      type: object
      properties:
        model:
          description: >-
            Model configuration object or model name string (e.g.,
            'openai/gpt-5-nano')
          anyOf:
            - $ref: '#/components/schemas/ModelConfig'
            - type: string
        timeout:
          description: Timeout in ms for the extraction
          example: 30000
          type: number
        selector:
          description: CSS selector to scope extraction to a specific element
          example: '#main-content'
          type: string
        ignoreSelectors:
          description: >-
            Selectors for elements and subtrees that should be excluded from
            extraction
          example:
            - nav
            - .cookie-banner
            - '#sidebar-ads'
          type: array
          items:
            type: string
        screenshot:
          description: >-
            When true, include a screenshot of the current viewport in the
            extraction LLM call. Defaults to false.
          example: false
          type: boolean
    ExtractResultOutput:
      type: object
      properties:
        result:
          description: Extracted data matching the requested schema
          x-stainless-any: true
        actionId:
          description: Action ID for tracking
          type: string
      required:
        - result
      additionalProperties: false
    ModelConfig:
      $ref: '#/components/schemas/ModelConfigObject'
    ModelConfigObject:
      anyOf:
        - $ref: '#/components/schemas/VertexModelConfigObject'
        - $ref: '#/components/schemas/AzureModelConfigObject'
        - $ref: '#/components/schemas/GenericModelConfigObject'
    VertexModelConfigObject:
      type: object
      properties:
        modelName:
          description: Model name string with provider prefix (e.g., 'openai/gpt-5-nano')
          example: openai/gpt-5.4-mini
          type: string
        apiKey:
          description: API key for the model provider
          example: sk-some-openai-api-key
          type: string
        baseURL:
          description: Base URL for the model provider
          example: https://api.openai.com/v1
          type: string
          format: uri
        headers:
          description: Custom headers sent with every request to the model provider
          type: object
          propertyNames:
            type: string
          additionalProperties:
            type: string
        provider:
          description: Vertex AI model provider
          type: string
          const: vertex
        auth:
          $ref: '#/components/schemas/GoogleServiceAccountAuth'
          description: Vertex provider authentication configuration
        providerOptions:
          $ref: '#/components/schemas/VertexModelProviderOptions'
          description: Vertex provider-specific model configuration
      required:
        - modelName
        - provider
        - auth
        - providerOptions
      additionalProperties: false
    AzureModelConfigObject:
      anyOf:
        - $ref: '#/components/schemas/AzureEntraModelConfigObject'
        - $ref: '#/components/schemas/AzureApiKeyModelConfigObject'
    GenericModelConfigObject:
      type: object
      properties:
        modelName:
          description: Model name string with provider prefix (e.g., 'openai/gpt-5-nano')
          example: openai/gpt-5.4-mini
          type: string
        apiKey:
          description: API key for the model provider
          example: sk-some-openai-api-key
          type: string
        baseURL:
          description: Base URL for the model provider
          example: https://api.openai.com/v1
          type: string
          format: uri
        headers:
          description: Custom headers sent with every request to the model provider
          type: object
          propertyNames:
            type: string
          additionalProperties:
            type: string
        provider:
          description: AI provider for the model (or provide a baseURL endpoint instead)
          example: openai
          type: string
          enum:
            - openai
            - anthropic
            - google
            - microsoft
            - bedrock
      required:
        - modelName
      additionalProperties: false
    GoogleServiceAccountAuth:
      type: object
      properties:
        type:
          description: >-
            Use inline Google Cloud service account credentials for provider
            authentication
          type: string
          const: googleServiceAccount
        credentials:
          $ref: '#/components/schemas/GoogleServiceAccountCredentials'
          description: Google Cloud service account credentials
        scopes:
          description: Google auth scopes for the desired API request
          anyOf:
            - type: string
            - type: array
              items:
                type: string
        projectId:
          description: Google Cloud project ID used by google-auth-library
          type: string
        universeDomain:
          description: Google Cloud universe domain
          type: string
      required:
        - type
        - credentials
      additionalProperties: false
    VertexModelProviderOptions:
      type: object
      properties:
        vertex:
          $ref: '#/components/schemas/VertexProviderOptions'
          description: Vertex AI provider-specific settings
      required:
        - vertex
      additionalProperties: false
    AzureEntraModelConfigObject:
      type: object
      properties:
        modelName:
          description: Model name string with provider prefix (e.g., 'openai/gpt-5-nano')
          example: openai/gpt-5.4-mini
          type: string
        baseURL:
          description: Base URL for the model provider
          example: https://api.openai.com/v1
          type: string
          format: uri
        headers:
          description: Custom headers sent with every request to the model provider
          type: object
          propertyNames:
            type: string
          additionalProperties:
            type: string
        provider:
          description: Azure OpenAI model provider
          type: string
          const: azure
        providerOptions:
          $ref: '#/components/schemas/AzureModelProviderOptions'
          description: Azure provider-specific model configuration
        auth:
          $ref: '#/components/schemas/AzureEntraIdAuth'
          description: Azure provider authentication configuration
      required:
        - modelName
        - provider
        - providerOptions
        - auth
      additionalProperties: false
    AzureApiKeyModelConfigObject:
      type: object
      properties:
        modelName:
          description: Model name string with provider prefix (e.g., 'openai/gpt-5-nano')
          example: openai/gpt-5.4-mini
          type: string
        apiKey:
          description: API key for the model provider
          example: sk-some-openai-api-key
          type: string
        baseURL:
          description: Base URL for the model provider
          example: https://api.openai.com/v1
          type: string
          format: uri
        headers:
          description: Custom headers sent with every request to the model provider
          type: object
          propertyNames:
            type: string
          additionalProperties:
            type: string
        provider:
          description: Azure OpenAI model provider
          type: string
          const: azure
        providerOptions:
          $ref: '#/components/schemas/AzureModelProviderOptions'
          description: Azure provider-specific model configuration
      required:
        - modelName
        - provider
        - providerOptions
      additionalProperties: false
    GoogleServiceAccountCredentials:
      type: object
      properties:
        type:
          type: string
          const: service_account
        project_id:
          type: string
        private_key_id:
          type: string
        private_key:
          type: string
        client_email:
          type: string
        client_id:
          type: string
        auth_uri:
          type: string
          format: uri
        token_uri:
          type: string
          format: uri
        auth_provider_x509_cert_url:
          type: string
          format: uri
        client_x509_cert_url:
          type: string
          format: uri
        universe_domain:
          type: string
      required:
        - private_key
        - client_email
      additionalProperties: false
    VertexProviderOptions:
      type: object
      properties:
        project:
          description: Google Cloud project ID for Vertex AI models
          example: my-gcp-project
          type: string
        location:
          description: Google Cloud location for Vertex AI models
          example: us-central1
          type: string
        baseURL:
          description: Base URL for the Vertex AI provider
          type: string
          format: uri
        headers:
          description: Custom headers sent with every request to the Vertex AI provider
          type: object
          propertyNames:
            type: string
          additionalProperties:
            type: string
      required:
        - project
        - location
      additionalProperties: false
    AzureModelProviderOptions:
      type: object
      properties:
        azure:
          $ref: '#/components/schemas/AzureProviderOptions'
          description: Azure OpenAI provider-specific settings
      required:
        - azure
      additionalProperties: false
    AzureEntraIdAuth:
      type: object
      properties:
        type:
          description: Use a Microsoft Entra ID bearer token for authentication
          type: string
          const: azureEntraId
        token:
          description: Microsoft Entra ID bearer token for Azure OpenAI
          type: string
          minLength: 1
      required:
        - type
        - token
      additionalProperties: false
    AzureProviderOptions:
      type: object
      properties:
        resourceName:
          description: Azure OpenAI resource name
          example: my-azure-openai-resource
          type: string
        baseURL:
          description: Base URL for the Azure OpenAI provider
          type: string
          format: uri
        apiVersion:
          description: Azure OpenAI API version
          example: 2024-10-01-preview
          type: string
        useDeploymentBasedUrls:
          description: Whether to use deployment-based Azure OpenAI URLs
          type: boolean
        headers:
          description: Custom headers sent with every request to the Azure OpenAI provider
          type: object
          propertyNames:
            type: string
          additionalProperties:
            type: string
      additionalProperties: false
  securitySchemes:
    BrowserbaseApiKey:
      type: apiKey
      in: header
      name: x-bb-api-key
      description: Browserbase API key for authentication
    BrowserbaseProjectId:
      type: apiKey
      in: header
      name: x-bb-project-id
      description: >-
        Deprecated. Browserbase API keys are now project-scoped, so this header
        is no longer required.

````