Skip to main content
POST
/
v1
/
sessions
/
{id}
/
agentExecute
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.execute('c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123', {
  agentConfig: {},
  executeOptions: {
    instruction: "Log in with username 'demo' and password 'test123', then navigate to settings",
  },
});

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.execute(
id="c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
agent_config={},
execute_options={
"instruction": "Log in with username 'demo' and password 'test123', then navigate to settings"
},
):
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.Execute(
context.TODO(),
"c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
stagehand.SessionExecuteParams{
AgentConfig: stagehand.SessionExecuteParamsAgentConfig{},
ExecuteOptions: stagehand.SessionExecuteParamsExecuteOptions{
Instruction: "Log in with username 'demo' and password 'test123', then navigate to settings",
},
},
)
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.SessionExecuteParams;
import com.browserbase.api.models.sessions.SessionExecuteResponse;

public final class Main {
private Main() {}

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

SessionExecuteParams params = SessionExecuteParams.builder()
.id("c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123")
.agentConfig(SessionExecuteParams.AgentConfig.builder().build())
.executeOptions(SessionExecuteParams.ExecuteOptions.builder()
.instruction("Log in with username 'demo' and password 'test123', then navigate to settings")
.build())
.build();
SessionExecuteResponse response = client.sessions().execute(params);
}
}
package com.browserbase.api.example

import com.browserbase.api.client.StagehandClient
import com.browserbase.api.client.okhttp.StagehandOkHttpClient
import com.browserbase.api.models.sessions.SessionExecuteParams
import com.browserbase.api.models.sessions.SessionExecuteResponse

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

val params: SessionExecuteParams = SessionExecuteParams.builder()
.id("c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123")
.agentConfig(SessionExecuteParams.AgentConfig.builder().build())
.executeOptions(SessionExecuteParams.ExecuteOptions.builder()
.instruction("Log in with username 'demo' and password 'test123', then navigate to settings")
.build())
.build()
val response: SessionExecuteResponse = client.sessions().execute(params)
}
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.execute(
"c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
agent_config: {},
execute_options: {instruction: "Log in with username 'demo' and password 'test123', then navigate to settings"}
)

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->execute(
'c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123',
agentConfig: [
'cua' => true,
'executionModel' => [
'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'],
],
'mode' => 'cua',
'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'],
],
'provider' => 'openai',
'systemPrompt' => 'systemPrompt',
],
executeOptions: [
'instruction' => 'Log in with username \'demo\' and password \'test123\', then navigate to settings',
'highlightCursor' => true,
'maxSteps' => 20,
'toolTimeout' => 30000,
'useSearch' => true,
'variables' => ['foo' => 'string'],
],
frameID: 'frameId',
shouldCache: true,
xStreamResponse: 'true',
);

var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}
using System;
using System.Collections.Generic;
using Stagehand;
using Stagehand.Models.Sessions;

StagehandClient client = new();

SessionExecuteParams parameters = new()
{
ID = "c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123",
AgentConfig = new()
{
Cua = true,
ExecutionModel = new ExecutionModelVertexModelConfigObject()
{
Auth = new()
{
Credentials = new()
{
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 = ExecutionModelVertexModelConfigObjectAuthCredentialsType.ServiceAccount,
UniverseDomain = "universe_domain",
},
ProjectID = "projectId",
Scopes = "string",
UniverseDomain = "universeDomain",
},
ModelName = "openai/gpt-5.4-mini",
ProviderOptions = new(
new ExecutionModelVertexModelConfigObjectProviderOptionsVertex()
{
Location = "us-central1",
Project = "my-gcp-project",
BaseUrl = "https://example.com",
Headers = new Dictionary<string, string>()
{
{ "foo", "string" }
},
}
),
ApiKey = "sk-some-openai-api-key",
BaseUrl = "https://api.openai.com/v1",
Headers = new Dictionary<string, string>() { { "foo", "string" } },
},
Mode = Mode.Cua,
Model = new AgentConfigModelVertexModelConfigObject()
{
Auth = new()
{
Credentials = new()
{
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 = AgentConfigModelVertexModelConfigObjectAuthCredentialsType.ServiceAccount,
UniverseDomain = "universe_domain",
},
ProjectID = "projectId",
Scopes = "string",
UniverseDomain = "universeDomain",
},
ModelName = "openai/gpt-5.4-mini",
ProviderOptions = new(
new AgentConfigModelVertexModelConfigObjectProviderOptionsVertex(

)
{
Location = "us-central1",
Project = "my-gcp-project",
BaseUrl = "https://example.com",
Headers = new Dictionary<string, string>()
{
{ "foo", "string" }
},
}
),
ApiKey = "sk-some-openai-api-key",
BaseUrl = "https://api.openai.com/v1",
Headers = new Dictionary<string, string>() { { "foo", "string" } },
},
Provider = AgentConfigProvider.OpenAI,
SystemPrompt = "systemPrompt",
},
ExecuteOptions = new()
{
Instruction = "Log in with username 'demo' and password 'test123', then navigate to settings",
HighlightCursor = true,
MaxSteps = 20,
ToolTimeout = 30000,
UseSearch = true,
Variables = new Dictionary<string, ExecuteOptionsVariable>()
{
{ "foo", "string" }
},
},
};

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

Console.WriteLine(response);
curl --request POST \
--url https://api.stagehand.browserbase.com/v1/sessions/{id}/agentExecute \
--header 'Content-Type: application/json' \
--header 'x-bb-api-key: <api-key>' \
--header 'x-bb-project-id: <api-key>' \
--data @- <<EOF
{
"agentConfig": {
"provider": "openai",
"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": {}
},
"systemPrompt": "<string>",
"cua": true,
"mode": "cua",
"executionModel": {
"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": {}
}
},
"executeOptions": {
"instruction": "Log in with username 'demo' and password 'test123', then navigate to settings",
"maxSteps": 20,
"highlightCursor": true,
"useSearch": true,
"toolTimeout": 30000,
"variables": {}
},
"frameId": "<string>",
"streamResponse": true,
"shouldCache": true
}
EOF
{
  "success": true,
  "data": {
    "result": {
      "success": true,
      "message": "Successfully logged in and navigated to dashboard",
      "actions": [
        {
          "type": "click",
          "reasoning": "<string>",
          "taskCompleted": true,
          "action": "<string>",
          "timeMs": 123,
          "pageText": "<string>",
          "pageUrl": "<string>",
          "instruction": "<string>"
        }
      ],
      "completed": true,
      "metadata": {},
      "usage": {
        "input_tokens": 1500,
        "output_tokens": 250,
        "inference_time_ms": 2500,
        "reasoning_tokens": 123,
        "cached_input_tokens": 123
      }
    },
    "cacheEntry": {
      "cacheKey": "<string>",
      "entry": "<unknown>"
    }
  }
}

Authorizations

x-bb-api-key
string
header
required

Browserbase API key for authentication

x-bb-project-id
string
header
required

Deprecated. Browserbase API keys are now project-scoped, so this header is no longer required.

Headers

x-stream-response
enum<string>

Whether to stream the response via SSE

Available options:
true,
false
Example:

"true"

Path Parameters

id
string
required

Unique session identifier

Example:

"c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123"

Body

application/json
agentConfig
object
required
executeOptions
object
required
frameId
string | null

Target frame ID for the agent

streamResponse
boolean

Whether to stream the response via SSE

Example:

true

shouldCache
boolean

If true, the server captures a cache entry and returns it to the client

Response

200 - application/json

Default Response

success
boolean
required

Indicates whether the request was successful

data
object
required