Get your Browserbase API key
Copy your API key from Browserbase settings.
Create a Box Server app
Open the Box Developer Console, then create a Server Authentication app with Client Credentials Grant.Enable these application scopes:
- Read all files and folders stored in Box
- Write all files and folders stored in Box
- Manage AI
Client Credentials Grant creates short-lived access tokens for the app’s service account at runtime. You don’t need an interactive login or a Box Developer Token.
Configure environment variables
Create your local environment file:Add your Browserbase and Box credentials:The example includes default SDS and label sources. Override them when you want to process a different pair:Each source link must start a browser download. Stagehand clicks the link, and the Browserbase Downloads API exposes the resulting file.
.env
.env
Review the workflow
The example uses Stagehand to find and click each document link. Browserbase stores the remote browser downloads, and the workflow retrieves the original bytes through the Downloads API. After it uploads the files, the workflow calls Box AI to:- Answer a safety question about the SDS with citations
- Extract structured SDS fields
- Extract label fields, including text embedded in the label artwork
- Return confidence scores and references for review
NEEDS_REVIEW.
Finally, the workflow adds these values to each file’s global properties metadata:
- Extracted compliance fields
- Browserbase session ID
- Source URL
- Document role
- Compliance status
Troubleshooting
Box AI isn’t ready
Box may need time to index a new file. The example retries readiness, rate-limit, and server responses with bounded exponential backoff before it stops.The browser opens a file instead of downloading it
Confirm that the source link starts a browser download. Update the source URL and accessible link name in.env, then use the Session Inspector to confirm that Stagehand clicks the expected link.
Box returns a permissions error
Confirm that the enterprise authorized the Server app, the app has the required file and Box AI scopes, and the destination folder grants its service account the Editor role.Next steps
Browserbase downloads
Learn how to retrieve files from Browserbase sessions.
Stagehand quickstart
Build browser agents with Stagehand and Browserbase.
Box AI structured extraction
Review the Box API fields, OCR support, and response format.
Box Client Credentials Grant
Configure unattended authentication for a Box service account.