Sign up for a free API key from Browser Use Cloud.New signups get $10 in free credits to try ChatBrowserUse - the fastest and most accurate model for browser automation.
You can also use OpenAI, Anthropic, Google, or any other supported provider. See LLM Providers for all options.
from browser_use import Agent, ChatBrowserUseimport asynciofrom dotenv import load_dotenvload_dotenv()async def main(): agent = Agent( task="Go to HackerNews and find the top Show HN post", llm=ChatBrowserUse(), ) result = await agent.run() print(result.final_result())if __name__ == "__main__": asyncio.run(main())
from browser_use import Agent, ChatBrowserUseimport asyncioasync def main(): agent = Agent( task="Search Google for 'what is browser automation' and tell me the top 3 results", llm=ChatBrowserUse(model='bu-2-0'), ) await agent.run()if __name__ == '__main__': asyncio.run(main())
from browser_use import Agent, ChatBrowserUseimport asyncioasync def main(): task = """ Go to https://httpbin.org/forms/post and fill out the form with: - Customer name: John Doe - Telephone: 555-123-4567 - Email: john.doe@example.com - Size: Medium - Topping: cheese Then submit the form and tell me the response. """ agent = Agent(task=task, llm=ChatBrowserUse()) await agent.run()if __name__ == '__main__': asyncio.run(main())
from browser_use import Agent, ChatBrowserUseimport asyncioasync def main(): task = """ Go to https://quotes.toscrape.com/ and extract: - The first 5 quotes - The author of each quote - The tags for each quote Format as: Quote 1: "[text]" - Author: [name] - Tags: [tags] """ agent = Agent(task=task, llm=ChatBrowserUse()) history = await agent.run() print(history.final_result())if __name__ == '__main__': asyncio.run(main())
from browser_use import Agent, ChatOpenAIfrom pydantic import BaseModelimport asyncioclass Post(BaseModel): post_title: str post_url: str num_comments: intclass Posts(BaseModel): posts: list[Post]async def main(): agent = Agent( task="Go to HackerNews Show HN and get the first 5 posts", llm=ChatOpenAI(model='gpt-4.1-mini'), output_model_schema=Posts ) history = await agent.run() result = history.final_result() if result: parsed = Posts.model_validate_json(result) for post in parsed.posts: print(f"Title: {post.post_title}") print(f"URL: {post.post_url}") print(f"Comments: {post.num_comments}") print("---")if __name__ == '__main__': asyncio.run(main())
The run() method returns an AgentHistoryList with useful information:
history = await agent.run()# Get resultsfinal_result = history.final_result() # Last extracted contentall_content = history.extracted_content() # All extracted data# Analyze executionhistory.is_done() # Check if completed successfullyhistory.urls() # All visited URLshistory.action_names() # All actions performedhistory.errors() # Any errors encountered# Screenshots and debugginghistory.screenshots() # All screenshots as base64history.screenshot_paths() # Paths to saved screenshots