1. Create a Session
Create a new browser session:
Write /tmp/request.json:
```json
{
"projectId": ""
}
```
```bash
bash -c 'curl -s -X POST "https://api.browserbase.com/v1/sessions" --header "Content-Type: application/json" --header "X-BB-API-Key: $BROWSERBASE_API_KEY" -d @/tmp/request.json'
```
With timeout and keepAlive:
Write /tmp/request.json:
```json
{
"projectId": "",
"timeout": 300,
"keepAlive": true
}
```
```bash
bash -c 'curl -s -X POST "https://api.browserbase.com/v1/sessions" --header "Content-Type: application/json" --header "X-BB-API-Key: $BROWSERBASE_API_KEY" -d @/tmp/request.json'
```
With proxy enabled (requires paid plan):
Write /tmp/request.json:
```json
{
"projectId": "",
"proxies": true
}
```
```bash
bash -c 'curl -s -X POST "https://api.browserbase.com/v1/sessions" --header "Content-Type: application/json" --header "X-BB-API-Key: $BROWSERBASE_API_KEY" -d @/tmp/request.json'
```
> Note: Proxies are not available on the free plan. You'll receive a 402 error if you try to use this feature without upgrading.
With specific region (us-west-2, us-east-1, eu-central-1, ap-southeast-1):
Write /tmp/request.json:
```json
{
"projectId": "",
"region": "us-west-2"
}
```
```bash
bash -c 'curl -s -X POST "https://api.browserbase.com/v1/sessions" --header "Content-Type: application/json" --header "X-BB-API-Key: $BROWSERBASE_API_KEY" -d @/tmp/request.json'
```
Response includes:
id - Session ID to use for connectionsconnectUrl - WebSocket URL for Playwright/PuppeteerseleniumRemoteUrl - URL for Selenium connectionssigningKey - Key for HTTP connections
2. List Sessions
List all sessions with optional filters:
```bash
bash -c 'curl -s -X GET "https://api.browserbase.com/v1/sessions" --header "X-BB-API-Key: $BROWSERBASE_API_KEY"'
```
Filter by status (RUNNING, ERROR, TIMED_OUT, COMPLETED):
```bash
bash -c 'curl -s -X GET "https://api.browserbase.com/v1/sessions?status=RUNNING" --header "X-BB-API-Key: $BROWSERBASE_API_KEY"'
```
Query by user metadata:
> Note: The query syntax for user metadata filtering uses single quotes: user_metadata['key']:'value'. To avoid complex shell escaping, write the query to a file and use --data-urlencode "q@filename".
Write /tmp/query.txt with content:
```
user_metadata['test']:'true'
```
Then query sessions:
```bash
bash -c 'curl -s -X GET -G "https://api.browserbase.com/v1/sessions" --data-urlencode "q@/tmp/query.txt" --header "X-BB-API-Key: $BROWSERBASE_API_KEY"'
```
More examples:
Query by stagehand metadata - write /tmp/query.txt:
```
user_metadata['stagehand']:'true'
```
Query by environment - write /tmp/query.txt:
```
user_metadata['env']:'production'
```
Then run:
```bash
bash -c 'curl -s -X GET -G "https://api.browserbase.com/v1/sessions" --data-urlencode "q@/tmp/query.txt" --header "X-BB-API-Key: $BROWSERBASE_API_KEY"'
```
3. Get Session Details
Get details of a specific session. Replace with the actual session ID:
```bash
bash -c 'curl -s -X GET "https://api.browserbase.com/v1/sessions/" --header "X-BB-API-Key: $BROWSERBASE_API_KEY"'
```
4. Update Session (Release)
Request to release a session before its timeout to avoid additional charges. Replace with the actual session ID:
Write /tmp/request.json:
```json
{
"status": "REQUEST_RELEASE"
}
```
```bash
bash -c 'curl -s -X POST "https://api.browserbase.com/v1/sessions/" --header "Content-Type: application/json" --header "X-BB-API-Key: $BROWSERBASE_API_KEY" -d @/tmp/request.json'
```
The session status will change to COMPLETED and endedAt timestamp will be set.
5. Get Debug/Live URLs
Get live debugging URLs for a running session. Replace with the actual session ID:
```bash
bash -c 'curl -s -X GET "https://api.browserbase.com/v1/sessions//debug" --header "X-BB-API-Key: $BROWSERBASE_API_KEY"'
```
> Note: Debug URLs may only be available after a browser client has connected to the session via WebSocket.
Response includes:
debuggerUrl - Chrome DevTools debugger URLdebuggerFullscreenUrl - Fullscreen debugger viewwsUrl - WebSocket URLpages - Array of open pages with their debugger URLs
6. Get Session Logs
Retrieve logs from a session. Replace with the actual session ID:
```bash
bash -c 'curl -s -X GET "https://api.browserbase.com/v1/sessions//logs" --header "X-BB-API-Key: $BROWSERBASE_API_KEY"'
```
7. Get Session Recording
Get the rrweb recording of a session. Replace with the actual session ID:
```bash
bash -c 'curl -s -X GET "https://api.browserbase.com/v1/sessions//recording" --header "X-BB-API-Key: $BROWSERBASE_API_KEY"'
```
8. Get Session Downloads
Retrieve files downloaded during a session (returns ZIP file). Replace with the actual session ID:
```bash
bash -c 'curl -s -X GET "https://api.browserbase.com/v1/sessions//downloads" --header "X-BB-API-Key: $BROWSERBASE_API_KEY"' --output downloads.zip
```
9. Upload Files to Session
Upload files to use in a browser session. Replace with the actual session ID:
```bash
bash -c 'curl -s -X POST "https://api.browserbase.com/v1/sessions//uploads" --header "X-BB-API-Key: $BROWSERBASE_API_KEY" -F "file=@/path/to/file.pdf"'
```
---