API Reference
Extract data from the page
Extracts structured data from the current page using AI-powered analysis.
POST
/
v1
/
sessions
/
{id}
/
extract
JavaScript
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);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)package main
import (
"context"
"fmt"
"github.com/browserbase/stagehand-go"
"github.com/browserbase/stagehand-go/option"
)
func main() {
client := stagehand.NewClient(
option.WithBrowserbaseAPIKey("My Browserbase API Key"),
option.WithBrowserbaseProjectID("My Browserbase Project ID"),
option.WithModelAPIKey("My Model API Key"),
)
response, err := client.Sessions.Extract(
context.TODO(),
"c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
stagehand.SessionExtractParams{},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Data)
}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");
}
}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")
}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)<?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();
}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);curl --request POST \
--url https://api.stagehand.browserbase.com/v1/sessions/{id}/extract \
--header 'Content-Type: application/json' \
--header 'x-bb-api-key: <api-key>' \
--header 'x-bb-project-id: <api-key>' \
--data '
{
"instruction": "Extract all product names and prices from the page",
"schema": {},
"options": {
"model": {
"modelName": "openai/gpt-5.4-mini",
"provider": "<string>",
"auth": {
"type": "<string>",
"credentials": {
"private_key": "<string>",
"client_email": "<string>",
"type": "<string>",
"project_id": "<string>",
"private_key_id": "<string>",
"client_id": "<string>",
"auth_uri": "<string>",
"token_uri": "<string>",
"auth_provider_x509_cert_url": "<string>",
"client_x509_cert_url": "<string>",
"universe_domain": "<string>"
},
"scopes": "<string>",
"projectId": "<string>",
"universeDomain": "<string>"
},
"providerOptions": {
"vertex": {
"project": "my-gcp-project",
"location": "us-central1",
"baseURL": "<string>",
"headers": {}
}
},
"apiKey": "sk-some-openai-api-key",
"baseURL": "https://api.openai.com/v1",
"headers": {}
},
"timeout": 30000,
"selector": "#main-content",
"ignoreSelectors": [
"nav",
".cookie-banner",
"#sidebar-ads"
],
"screenshot": false
},
"frameId": "<string>",
"streamResponse": true
}
'{
"success": true,
"data": {
"result": "<unknown>",
"actionId": "<string>"
}
}Authorizations
Browserbase API key for authentication
Deprecated. Browserbase API keys are now project-scoped, so this header is no longer required.
Headers
Whether to stream the response via SSE
Available options:
true, false Example:
"true"
Path Parameters
Unique session identifier
Example:
"c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123"
Body
application/json
Natural language instruction for what to extract
Example:
"Extract all product names and prices from the page"
JSON Schema defining the structure of data to extract
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Target frame ID for the extraction
Whether to stream the response via SSE
Example:
true
Previous
Execute an AI agentRuns an autonomous AI agent that can perform complex multi-step browser tasks.
Next
⌘I
JavaScript
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);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)package main
import (
"context"
"fmt"
"github.com/browserbase/stagehand-go"
"github.com/browserbase/stagehand-go/option"
)
func main() {
client := stagehand.NewClient(
option.WithBrowserbaseAPIKey("My Browserbase API Key"),
option.WithBrowserbaseProjectID("My Browserbase Project ID"),
option.WithModelAPIKey("My Model API Key"),
)
response, err := client.Sessions.Extract(
context.TODO(),
"c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
stagehand.SessionExtractParams{},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Data)
}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");
}
}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")
}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)<?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();
}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);curl --request POST \
--url https://api.stagehand.browserbase.com/v1/sessions/{id}/extract \
--header 'Content-Type: application/json' \
--header 'x-bb-api-key: <api-key>' \
--header 'x-bb-project-id: <api-key>' \
--data '
{
"instruction": "Extract all product names and prices from the page",
"schema": {},
"options": {
"model": {
"modelName": "openai/gpt-5.4-mini",
"provider": "<string>",
"auth": {
"type": "<string>",
"credentials": {
"private_key": "<string>",
"client_email": "<string>",
"type": "<string>",
"project_id": "<string>",
"private_key_id": "<string>",
"client_id": "<string>",
"auth_uri": "<string>",
"token_uri": "<string>",
"auth_provider_x509_cert_url": "<string>",
"client_x509_cert_url": "<string>",
"universe_domain": "<string>"
},
"scopes": "<string>",
"projectId": "<string>",
"universeDomain": "<string>"
},
"providerOptions": {
"vertex": {
"project": "my-gcp-project",
"location": "us-central1",
"baseURL": "<string>",
"headers": {}
}
},
"apiKey": "sk-some-openai-api-key",
"baseURL": "https://api.openai.com/v1",
"headers": {}
},
"timeout": 30000,
"selector": "#main-content",
"ignoreSelectors": [
"nav",
".cookie-banner",
"#sidebar-ads"
],
"screenshot": false
},
"frameId": "<string>",
"streamResponse": true
}
'{
"success": true,
"data": {
"result": "<unknown>",
"actionId": "<string>"
}
}
