### Installation and Basic Usage Source: https://docs.cloud.browser-use.com/index Instructions on how to install the Browser Use SDK and a basic example of creating and completing a task using the API. ```APIDOC ## Installation ### Python ```bash pip install browser-use-sdk ``` ### Environment Variable Set your API key in the `.env` file: ``` BROWSER_USE_API_KEY=bu_... ``` ## Basic Task Creation and Completion ### Description This example demonstrates how to initialize the client, create a task, and retrieve its result. ### Method POST (for task creation), GET (for task completion status/result) ### Endpoint `/tasks` (for creation), `/tasks/{taskId}` (for completion) ### Parameters #### Request Body (for task creation) - **task** (string) - Required - The description of the task to be automated. ### Request Example (TypeScript) ```typescript import { BrowserUseClient } from "browser-use-sdk"; const client = new BrowserUseClient({ apiKey: "bu_...", // Optional if BROWSER_USE_API_KEY is set }); const task = await client.tasks.createTask({ task: "Search for the top 10 Hacker News posts and return the title and url.", }); const result = await task.complete(); console.log(result.output); ``` ### Response #### Success Response (200) - **output** (any) - The result of the completed task. #### Response Example ```json { "output": { "title": "Example Title", "url": "http://example.com" } } ``` ##### Note The `apiKey` parameter is optional if you set the `BROWSER_USE_API_KEY` environment variable. ``` -------------------------------- ### Install Browser Use SDK (Python) Source: https://docs.cloud.browser-use.com/index Installs the browser-use-sdk package using pip. This is the first step to integrating Browser Use Cloud into your Python projects. ```python pip install browser-use-sdk ``` -------------------------------- ### Install Browser Use Cloud SDK Source: https://docs.cloud.browser-use.com/get-started/human-quickstart Install the Browser Use Cloud SDK using your preferred package manager. This SDK allows you to interact with the Browser Use Cloud API to automate browser tasks. ```sh pip install browser-use-sdk ``` ```sh npm install browser-use-sdk ``` ```sh pnpm add browser-use-sdk ``` ```sh yarn add browser-use-sdk ``` ```sh bun add browser-use-sdk ``` -------------------------------- ### Fetch Marketplace Skills - Go SDK Example Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills-marketplace/list-skills-marketplace-skills-get This Go code example illustrates how to fetch marketplace skills using the standard 'net/http' package. It constructs a GET request, sends it, reads the response body, and prints both the response status and the body content. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/marketplace/skills" req, _ := http.NewRequest("GET", url, nil) res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Get Profile using Go HTTP Client Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/profiles/get-profile-profiles-profile-id-get This Go code example shows how to fetch profile details using the standard net/http package. It constructs an HTTP GET request, sets the necessary API key header, and prints the response status and body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/profiles/profile_id" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-Browser-Use-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Fetch Marketplace Skills - PHP SDK Example Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills-marketplace/list-skills-marketplace-skills-get This PHP code snippet demonstrates fetching marketplace skills using the Guzzle HTTP client. It initializes a client, makes a GET request to the skills endpoint, and echoes the response body. ```php request('GET', 'https://api.browser-use.com/api/v2/marketplace/skills'); echo $response->getBody(); ``` -------------------------------- ### Fetch Marketplace Skills - Ruby SDK Example Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills-marketplace/list-skills-marketplace-skills-get This Ruby code snippet demonstrates fetching marketplace skills via the Cloud Browser Use API using the 'net/http' library. It sets up an HTTP client, makes a GET request to the specified URL, and outputs the response body. ```ruby require 'uri' require 'net/http' url = URI("https://api.browser-use.com/api/v2/marketplace/skills") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) response = http.request(request) puts response.read_body ``` -------------------------------- ### Fetch Tasks using Go SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/tasks/list-tasks-tasks-get This Go code example illustrates how to make a GET request to the Cloud Browser Use API to fetch tasks. It utilizes the standard 'net/http' package and requires an API key. The response status and body are printed. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/tasks" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-Browser-Use-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Fetch Session Data using Go SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/sessions/get-session-sessions-session-id-get This Go code example illustrates how to get session information from the Cloud Browser API. It constructs an HTTP GET request, adds the necessary API key header, and prints the response status and body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/sessions/session_id" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-Browser-Use-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Fetch Marketplace Skills - C# SDK Example Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills-marketplace/list-skills-marketplace-skills-get This C# code snippet illustrates fetching marketplace skills using the RestSharp library. It sets up a REST client for the specified URL and executes a GET request, capturing the response. ```csharp var client = new RestClient("https://api.browser-use.com/api/v2/marketplace/skills"); var request = new RestRequest(Method.GET); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Fetch Marketplace Skills - Python SDK Example Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills-marketplace/list-skills-marketplace-skills-get This Python code snippet demonstrates how to fetch a list of marketplace skills from the Cloud Browser Use API using the 'requests' library. It sends a GET request to the skills endpoint and prints the JSON response. ```python import requests url = "https://api.browser-use.com/api/v2/marketplace/skills" response = requests.get(url) print(response.json()) ``` -------------------------------- ### Fetch Browsers from Cloud Browser API (Python, JavaScript, Go, Ruby, Java, PHP, C#, Swift) Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/browsers/list-browser-sessions-browsers-get These examples demonstrate how to make a GET request to the /api/v2/browsers endpoint of the Cloud Browser API. They show how to include the required 'X-Browser-Use-API-Key' header for authentication. Each example is tailored to the specific syntax and libraries of its respective programming language. ```python import requests url = "https://api.browser-use.com/api/v2/browsers" headers = {"X-Browser-Use-API-Key": ""} response = requests.get(url, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.browser-use.com/api/v2/browsers'; const options = {method: 'GET', headers: {'X-Browser-Use-API-Key': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/browsers" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-Browser-Use-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.browser-use.com/api/v2/browsers") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["X-Browser-Use-API-Key"] = '' response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.get("https://api.browser-use.com/api/v2/browsers") .header("X-Browser-Use-API-Key", "") .asString(); ``` ```php request('GET', 'https://api.browser-use.com/api/v2/browsers', [ 'headers' => [ 'X-Browser-Use-API-Key' => '', ], ]); echo $response->getBody(); ?> ``` ```csharp var client = new RestClient("https://api.browser-use.com/api/v2/browsers"); var request = new RestRequest(Method.GET); request.AddHeader("X-Browser-Use-API-Key", ""); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["X-Browser-Use-API-Key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.browser-use.com/api/v2/browsers")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Fetch Marketplace Skills - Swift SDK Example Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills-marketplace/list-skills-marketplace-skills-get This Swift code snippet demonstrates fetching marketplace skills using URLSession. It creates an NSMutableURLRequest for a GET request to the skills endpoint and initiates a data task to handle the response. ```swift import Foundation let request = NSMutableURLRequest(url: NSURL(string: "https://api.browser-use.com/api/v2/marketplace/skills")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Fetch Task Output Files using Cloud Browser Use API Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/files/get-task-output-file-presigned-url-files-tasks-task-id-output-files-file-id-get Demonstrates how to retrieve output files for a specific task from the Cloud Browser Use API. Requires an API key for authentication. The examples show making a GET request to the specified endpoint and handling the response. ```python import requests url = "https://api.browser-use.com/api/v2/files/tasks/task_id/output-files/file_id" headers = {"X-Browser-Use-API-Key": ""} response = requests.get(url, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.browser-use.com/api/v2/files/tasks/task_id/output-files/file_id'; const options = {method: 'GET', headers: {'X-Browser-Use-API-Key': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/files/tasks/task_id/output-files/file_id" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-Browser-Use-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.browser-use.com/api/v2/files/tasks/task_id/output-files/file_id") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["X-Browser-Use-API-Key"] = '' response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.get("https://api.browser-use.com/api/v2/files/tasks/task_id/output-files/file_id") .header("X-Browser-Use-API-Key", "") .asString(); ``` ```php request('GET', 'https://api.browser-use.com/api/v2/files/tasks/task_id/output-files/file_id', [ 'headers' => [ 'X-Browser-Use-API-Key' => '', ], ]); echo $response->getBody(); ?> ``` ```csharp var client = new RestClient("https://api.browser-use.com/api/v2/files/tasks/task_id/output-files/file_id"); var request = new RestRequest(Method.GET); request.AddHeader("X-Browser-Use-API-Key", ""); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["X-Browser-Use-API-Key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.browser-use.com/api/v2/files/tasks/task_id/output-files/file_id")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Fetch Marketplace Skills - Java SDK Example Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills-marketplace/list-skills-marketplace-skills-get This Java code snippet shows how to retrieve marketplace skills using the Unirest library. It performs a GET request to the skills endpoint and captures the response as a String. ```java HttpResponse response = Unirest.get("https://api.browser-use.com/api/v2/marketplace/skills") .asString(); ``` -------------------------------- ### API Reference and Next Steps Source: https://docs.cloud.browser-use.com/index Information on accessing the full API reference and exploring advanced features. ```APIDOC ## Next Steps Explore advanced features and resources: ### Stealth Browser stealth mode. ### Structured Output Get structured data. ### Streaming Response Monitor task progress. ### API Reference Access detailed API documentation. ``` -------------------------------- ### Generate Presigned URL for File Upload (Python) Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/files/agent-session-upload-file-presigned-url-files-sessions-session-id-presigned-url-post This Python example uses the 'requests' library to send a POST request to the Cloud Browser API to get a presigned URL. It includes the necessary headers and a JSON payload specifying file details. Ensure the 'requests' library is installed. ```python import requests url = "https://api.browser-use.com/api/v2/files/sessions/session_id/presigned-url" payload = { "fileName": "string", "contentType": "image/jpg", "sizeBytes": 1 } headers = { "X-Browser-Use-API-Key": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` -------------------------------- ### Get Task Logs - Swift Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/tasks/get-task-logs-tasks-task-id-logs-get Swift example using URLSession to retrieve task logs. It creates an NSMutableURLRequest with the GET method and API key, then executes the request. ```swift import Foundation let headers = ["X-Browser-Use-API-Key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.browser-use.com/api/v2/tasks/task_id/logs")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Get Task Logs - C# Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/tasks/get-task-logs-tasks-task-id-logs-get C# example using RestSharp to fetch task logs. It configures a GET request with the API key in the headers and executes the request. ```csharp var client = new RestClient("https://api.browser-use.com/api/v2/tasks/task_id/logs"); var request = new RestRequest(Method.GET); request.AddHeader("X-Browser-Use-API-Key", ""); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Get Task Logs - PHP Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/tasks/get-task-logs-tasks-task-id-logs-get PHP example using GuzzleHttp to retrieve task logs. It sends a GET request to the API with the required API key in the headers. ```php request('GET', 'https://api.browser-use.com/api/v2/tasks/task_id/logs', [ 'headers' => [ 'X-Browser-Use-API-Key' => '', ], ]); echo $response->getBody(); ``` -------------------------------- ### Get Task Logs - Java Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/tasks/get-task-logs-tasks-task-id-logs-get Java example using the Unirest library to fetch task logs. It makes a GET request to the API endpoint and includes the API key as a header. ```java HttpResponse response = Unirest.get("https://api.browser-use.com/api/v2/tasks/task_id/logs") .header("X-Browser-Use-API-Key", "") .asString(); ``` -------------------------------- ### Core Concepts Overview Source: https://docs.cloud.browser-use.com/index An overview of the fundamental concepts in Browser Use Cloud, including Task, Session, and Profile. ```APIDOC ## Understanding Core Concepts Browser Use Cloud is built around several key concepts: ### Overview Learn how all concepts work together. ### Task Understand automation jobs and execution. ### Session Master stateful browser environments. ### Profile Preserve user state across automations. ``` -------------------------------- ### Get Task Logs - Python Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/tasks/get-task-logs-tasks-task-id-logs-get Python example using the requests library to fetch task logs. It sends a GET request to the API endpoint with the necessary API key in the headers. ```python import requests url = "https://api.browser-use.com/api/v2/tasks/task_id/logs" headers = {"X-Browser-Use-API-Key": ""} response = requests.get(url, headers=headers) print(response.json()) ``` -------------------------------- ### Set API Key and Use Browser Use Cloud API Source: https://docs.cloud.browser-use.com/get-started/human-quickstart Configure your API key, either directly in the client or via an environment variable, and then use the SDK to create and complete tasks. The example demonstrates searching for Hacker News posts. ```typescript import { BrowserUseClient } from "browser-use-sdk"; const client = new BrowserUseClient({ apiKey: "bu_...", // Optional if BROWSER_USE_API_KEY is set }); const task = await client.tasks.createTask({ task: "Search for the top 10 Hacker News posts and return the title and url.", }); const result = await task.complete(); console.log(result.output); ``` ```python from browser_use_sdk import BrowserUse client = BrowserUse(api_key="bu_...") task = client.tasks.create_task( task="Search for the top 10 Hacker News posts and return the title and url.", llm="browser-use-llm" ) result = task.complete() result.output ``` -------------------------------- ### Create and Complete a Task with Browser Use SDK (TypeScript) Source: https://docs.cloud.browser-use.com/index Demonstrates how to initialize the BrowserUseClient and create a task to search for Hacker News posts. The task is then completed, and the output is logged. The API key can be provided during client initialization or via the BROWSER_USE_API_KEY environment variable. ```typescript import { BrowserUseClient } from "browser-use-sdk"; const client = new BrowserUseClient({ apiKey: "bu_...", // Optional if BROWSER_USE_API_KEY is set }); const task = await client.tasks.createTask({ task: "Search for the top 10 Hacker News posts and return the title and url.", }); const result = await task.complete(); console.log(result.output); ``` -------------------------------- ### Get Skill Execution Output - C# SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills/get-skill-execution-output-skills-skill-id-executions-execution-id-output-get Example of how to get the presigned URL for downloading skill execution output using the RestSharp library in C#. It configures a GET request with the API key header and executes the request. ```csharp var client = new RestClient("https://api.browser-use.com/api/v2/skills/skill_id/executions/execution_id/output"); var request = new RestRequest(Method.GET); request.AddHeader("X-Browser-Use-API-Key", ""); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Get Task Logs - Go Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/tasks/get-task-logs-tasks-task-id-logs-get Go example demonstrating how to fetch task logs using the net/http package. It constructs an HTTP GET request with the API key and prints the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/tasks/task_id/logs" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-Browser-Use-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Get Task Logs - JavaScript Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/tasks/get-task-logs-tasks-task-id-logs-get JavaScript example using the fetch API to retrieve task logs. It makes a GET request to the specified URL, including the API key in the request headers. ```javascript const url = 'https://api.browser-use.com/api/v2/tasks/task_id/logs'; const options = {method: 'GET', headers: {'X-Browser-Use-API-Key': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` -------------------------------- ### Create Profile using Cloud Browser Use API (Python, JavaScript, Go, Ruby, Java, PHP, C#, Swift) Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/profiles/create-profile-profiles-post These examples demonstrate how to create a new profile using the Cloud Browser Use API. They show requests made with different programming languages, including Python, JavaScript, Go, Ruby, Java, PHP, C#, and Swift. Ensure you replace '' with your actual API key. The API expects a JSON payload, and these examples send an empty JSON object '{}'. ```python import requests url = "https://api.browser-use.com/api/v2/profiles" payload = {} headers = { "X-Browser-Use-API-Key": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.browser-use.com/api/v2/profiles'; const options = { method: 'POST', headers: {'X-Browser-Use-API-Key': '', 'Content-Type': 'application/json'}, body: '{}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/profiles" payload := strings.NewReader("{}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("X-Browser-Use-API-Key", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.browser-use.com/api/v2/profiles") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["X-Browser-Use-API-Key"] = '' request["Content-Type"] = 'application/json' request.body = "{}" response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.post("https://api.browser-use.com/api/v2/profiles") .header("X-Browser-Use-API-Key", "") .header("Content-Type", "application/json") .body("{}") .asString(); ``` ```php request('POST', 'https://api.browser-use.com/api/v2/profiles', [ 'body' => '{}', 'headers' => [ 'Content-Type' => 'application/json', 'X-Browser-Use-API-Key' => '', ], ]); echo $response->getBody(); ``` ```csharp var client = new RestClient("https://api.browser-use.com/api/v2/profiles"); var request = new RestRequest(Method.POST); request.AddHeader("X-Browser-Use-API-Key", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "X-Browser-Use-API-Key": "", "Content-Type": "application/json" ] let parameters = [] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.browser-use.com/api/v2/profiles")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Get Skill Execution Output - JavaScript SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills/get-skill-execution-output-skills-skill-id-executions-execution-id-output-get Example of how to get the presigned URL for downloading skill execution output using JavaScript's fetch API. It makes a GET request and handles the JSON response or potential errors. ```javascript const url = 'https://api.browser-use.com/api/v2/skills/skill_id/executions/execution_id/output'; const options = {method: 'GET', headers: {'X-Browser-Use-API-Key': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` -------------------------------- ### Execute Skill via API (Go) Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills-marketplace/execute-skill-marketplace-skills-skill-id-execute-post This Go code example shows how to make a POST request to the Cloud Browser API to execute a skill. It utilizes the `net/http` package and requires an API key. The request body and headers are set, and both the response status and body are printed. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/marketplace/skills/skill_id/execute" payload := strings.NewReader("{}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("X-Browser-Use-API-Key", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Get Skill Execution Output - Python SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills/get-skill-execution-output-skills-skill-id-executions-execution-id-output-get Example of how to get the presigned URL for downloading skill execution output using Python's requests library. It sends a GET request to the API endpoint with the necessary API key. ```python import requests url = "https://api.browser-use.com/api/v2/skills/skill_id/executions/execution_id/output" headers = {"X-Browser-Use-API-Key": ""} response = requests.get(url, headers=headers) print(response.json()) ``` -------------------------------- ### Get Skill Execution Output - Swift SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills/get-skill-execution-output-skills-skill-id-executions-execution-id-output-get Example of how to get the presigned URL for downloading skill execution output using Swift's URLSession. It sets up an NSMutableURLRequest with the GET method and API key header, then initiates a data task. ```swift import Foundation let headers = ["X-Browser-Use-API-Key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.browser-use.com/api/v2/skills/skill_id/executions/execution_id/output")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Get Skill Execution Output - Java SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills/get-skill-execution-output-skills-skill-id-executions-execution-id-output-get Example of how to get the presigned URL for downloading skill execution output using the Unirest Java library. It performs a GET request with the specified API key header and returns the response as a string. ```java HttpResponse response = Unirest.get("https://api.browser-use.com/api/v2/skills/skill_id/executions/execution_id/output") .header("X-Browser-Use-API-Key", "") .asString(); ``` -------------------------------- ### Fetch Task Details using Cloud Browser API (Go) Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/tasks/get-task-tasks-task-id-get This Go code example illustrates how to fetch task details from the Cloud Browser API. It constructs an HTTP GET request, sets the required API key header, and sends the request using the default HTTP client. The response body is then read and printed. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/tasks/task_id" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-Browser-Use-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Create and Complete a Task (Python) Source: https://docs.cloud.browser-use.com/concepts/task Shows how to initiate a task with specific instructions and then execute it to retrieve the output using the browser_use_sdk. Requires the SDK to be installed and a valid API key. ```python from browser_use_sdk import BrowserUse client = BrowserUse(api_key="bu_...") task = client.tasks.create_task( task="Search for top 10 Hacker News posts", llm="browser-use-llm" ) result = task.complete() print(result.output) ``` -------------------------------- ### Get Skill Execution Output - PHP SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills/get-skill-execution-output-skills-skill-id-executions-execution-id-output-get Example of how to get the presigned URL for downloading skill execution output using the Guzzle HTTP client in PHP. It sends a GET request with the required API key header and echoes the response body. ```php request('GET', 'https://api.browser-use.com/api/v2/skills/skill_id/executions/execution_id/output', [ 'headers' => [ 'X-Browser-Use-API-Key' => '', ], ]); echo $response->getBody(); ``` -------------------------------- ### Get Skill Execution Output - Go SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills/get-skill-execution-output-skills-skill-id-executions-execution-id-output-get Example of how to get the presigned URL for downloading skill execution output using Go's net/http package. It constructs a GET request, adds the API key header, and prints the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/skills/skill_id/executions/execution_id/output" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-Browser-Use-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Configure API Key for Browser Use Cloud Source: https://docs.cloud.browser-use.com/index Sets the Browser Use Cloud API key in the .env file. This key is required for authenticating your requests to the Browser Use Cloud API. Ensure you replace 'bu_...' with your actual API key. ```env BROWSER_USE_API_KEY=bu_... ``` -------------------------------- ### Create Browser Session using Go SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/browsers/create-browser-session-browsers-post This Go code example demonstrates how to create a browser session by making an HTTP POST request to the /api/v2/browsers endpoint. It constructs the request with the required headers, including the API key, and sends an empty JSON payload. The response body and status are then printed. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/browsers" payload := strings.NewReader("{}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("X-Browser-Use-API-Key", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Get Profile using C# RestSharp Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/profiles/get-profile-profiles-profile-id-get This C# code example uses the RestSharp library to make a GET request to the Browser-Use API for profile details. It configures the request with the API key header and executes it, returning the IRestResponse. ```csharp var client = new RestClient("https://api.browser-use.com/api/v2/profiles/profile_id"); var request = new RestRequest(Method.GET); request.AddHeader("X-Browser-Use-API-Key", ""); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Get Profile using Java Unirest Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/profiles/get-profile-profiles-profile-id-get This Java code example uses the Unirest library to make a GET request to retrieve profile details. It sets the API key as a header and executes the request, returning the response as a string. ```java HttpResponse response = Unirest.get("https://api.browser-use.com/api/v2/profiles/profile_id") .header("X-Browser-Use-API-Key", "") .asString(); ``` -------------------------------- ### Generate Presigned URL for File Upload (Go) Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/files/agent-session-upload-file-presigned-url-files-sessions-session-id-presigned-url-post This Go example utilizes the standard 'net/http' package to perform a POST request to the Cloud Browser API. It constructs the request with appropriate headers and a JSON payload. Ensure proper error handling for production code. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/files/sessions/session_id/presigned-url" payload := strings.NewReader("{\n \"fileName\": \"string\",\n \"contentType\": \"image/jpg\",\n \"sizeBytes\": 1\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("X-Browser-Use-API-Key", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Create Session using Go SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/sessions/create-session-sessions-post This Go program illustrates how to create a new session using the Browser Use API. It constructs an HTTP POST request with the necessary headers and an empty JSON payload. The response body is then printed to the console. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/sessions" payload := strings.NewReader("{}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("X-Browser-Use-API-Key", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Get Task Status using Browser-Use API v2 Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/tasks/get-task-status-tasks-task-id-status-get These examples show how to make a GET request to the Browser-Use API v2 to check the status of a specific task. They require an API key for authentication and return the task's status information. ```python import requests url = "https://api.browser-use.com/api/v2/tasks/task_id/status" headers = {"X-Browser-Use-API-Key": ""} response = requests.get(url, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.browser-use.com/api/v2/tasks/task_id/status'; const options = {method: 'GET', headers: {'X-Browser-Use-API-Key': ''}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.browser-use.com/api/v2/tasks/task_id/status" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("X-Browser-Use-API-Key", "") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.browser-use.com/api/v2/tasks/task_id/status") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["X-Browser-Use-API-Key"] = '' response = http.request(request) puts response.read_body ``` ```java HttpResponse response = Unirest.get("https://api.browser-use.com/api/v2/tasks/task_id/status") .header("X-Browser-Use-API-Key", "") .asString(); ``` ```php request('GET', 'https://api.browser-use.com/api/v2/tasks/task_id/status', [ 'headers' => [ 'X-Browser-Use-API-Key' => '', ], ]); echo $response->getBody(); ?> ``` ```csharp var client = new RestClient("https://api.browser-use.com/api/v2/tasks/task_id/status"); var request = new RestRequest(Method.GET); request.AddHeader("X-Browser-Use-API-Key", ""); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["X-Browser-Use-API-Key": ""] let request = NSMutableURLRequest(url: NSURL(string: "https://api.browser-use.com/api/v2/tasks/task_id/status")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Get Skill Execution Output - Ruby SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/skills/get-skill-execution-output-skills-skill-id-executions-execution-id-output-get Example of how to get the presigned URL for downloading skill execution output using Ruby's net/http library. It sets up an HTTPS request, adds the API key header, and outputs the response body. ```ruby require 'uri' require 'net/http' url = URI("https://api.browser-use.com/api/v2/skills/skill_id/executions/execution_id/output") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["X-Browser-Use-API-Key"] = '' response = http.request(request) puts response.read_body ``` -------------------------------- ### Create Session using JavaScript SDK Source: https://docs.cloud.browser-use.com/api-reference/api-v-2/sessions/create-session-sessions-post This JavaScript example shows how to create a new session via the Browser Use API using the Fetch API. It sends a POST request to the specified URL, including the API key in the headers and an empty JSON object as the request body. Error handling is included for network issues. ```javascript const url = 'https://api.browser-use.com/api/v2/sessions'; const options = { method: 'POST', headers: {'X-Browser-Use-API-Key': '', 'Content-Type': 'application/json'}, body: '{}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ```