browsa Python package 0.1.3: Browser(cdp_url=..., headers=...) connected and opened https://example.com. We didn't run the model step, which needs your OpenAI key; that part follows browser-use's own README.Prerequisites
- A Browsa API key (it starts with
agt_). Sign up for 100 free credits, no card. - Python 3.11 or newer (browser-use's minimum).
- A model key. The script uses OpenAI through browser-use's
ChatOpenAI; browser-use also shipsChatAnthropicand others.
Install
pip install browser-use browsaThen put your keys in the environment:
export BROWSA_API_KEY="agt_live_..."
export OPENAI_API_KEY="sk-..."You don't need a local Chrome or playwright install: the browser runs on Browsa.
The script
One file. It starts a 5-minute Browsa browser, gives it to a browser-use Agent, prints the result and destroys the browser, even if the agent fails.
import asyncio
import os
from browsa import Client
from browser_use import Agent, Browser, ChatOpenAI
BROWSA_API_KEY = os.environ["BROWSA_API_KEY"]
TASK = "Open https://example.com, follow its link, and tell me the title of the page you land on."
async def main():
browsa = Client(api_key=BROWSA_API_KEY)
cloud = browsa.create_agent(ttl="5m") # a Browsa cloud browser, 1 credit
try:
browser = Browser(
cdp_url=cloud["cdp_http"],
headers={"X-API-Key": BROWSA_API_KEY},
)
agent = Agent(
task=TASK,
llm=ChatOpenAI(model="gpt-5.6-luna"), # reads OPENAI_API_KEY
browser=browser,
)
history = await agent.run(max_steps=15)
print(history.final_result())
finally:
browsa.destroy_agent(cloud["id"])
asyncio.run(main())Run it:
python agent.pyHow it works
- Start a browser.
create_agent(ttl="5m")starts a Chromium on Browsa and returns its id and itscdp_httpaddress. - Hand it to browser-use.
Browser(cdp_url=..., headers=...)attaches instead of launching. browser-use reads/json/versionat that address and opens the CDP WebSocket, sending yourX-API-Keyheader on both. - Run and clean up.
agent.run()drives the page with your model. browser-use closes its connection when the run ends, anddestroy_agent()infinallyshuts the Browsa browser down even if something fails.
Troubleshooting
401 Unauthorized when connecting
The X-API-Key header didn't reach Browsa, or the key is wrong. Check that BROWSA_API_KEY is set in the shell that runs the script and that it starts with agt_; the Browsa SDK refuses keys that don't. Pass the header exactly as the script does.
The connection drops after a few minutes
The browser reached the end of its TTL and shut down. The scripts use ttl="5m" (1 credit). For longer runs, ask for more, up to "1h"; any TTL over 5 minutes costs 5 credits. Start a new browser for the next run.
Use a different model
Swap the llm= line for another browser-use chat class, for example ChatAnthropic, and set that provider's key. The Browsa part of the script doesn't change.
max_steps reached before the task is done
Raise max_steps and the TTL together, so the browser outlives the agent.
Next steps
Turn the task into a scheduled job, or try the same browser with Stagehand or the OpenAI Agents SDK.