Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

fix: unify CLI cloud auth so cloud connect uses ~/.browser-use/config.json

ShawnPanaae93cee5c22e
diff --git a/browser_use/skill_cli/commands/cloud.py b/browser_use/skill_cli/commands/cloud.py
index e695186d4..2c6df8a6f 100644
--- a/browser_use/skill_cli/commands/cloud.py
+++ b/browser_use/skill_cli/commands/cloud.py
@@ -69,14 +69,18 @@ def _write_config(data: dict) -> None:
pass
-def _get_api_key() -> str:
- """Return API key from env var or config file. Exits with error if missing."""
+def _get_api_key_or_none() -> str | None:
+ """Return API key from env var or CLI config file, or None if not found."""
key = os.environ.get('BROWSER_USE_API_KEY')
if key:
return key
-
config = _read_config()
- key = config.get('api_key')
+ return config.get('api_key')
+
+
+def _get_api_key() -> str:
+ """Return API key from env var or config file. Exits with error if missing."""
+ key = _get_api_key_or_none()
if key:
return key
diff --git a/browser_use/skill_cli/main.py b/browser_use/skill_cli/main.py
index dfb181795..88f6780df 100755
--- a/browser_use/skill_cli/main.py
+++ b/browser_use/skill_cli/main.py
@@ -307,6 +307,16 @@ def ensure_daemon(
# Set up environment
env = os.environ.copy()
+ # For cloud mode, ensure the daemon has the API key from CLI config (~/.browser-use/config.json).
+ # CloudBrowserClient checks BROWSER_USE_API_KEY env var first, so injecting it here
+ # prevents the library from falling back to ~/.config/browseruse/cloud_auth.json.
+ if use_cloud and 'BROWSER_USE_API_KEY' not in env:
+ from browser_use.skill_cli.commands.cloud import _get_api_key_or_none
+
+ cli_api_key = _get_api_key_or_none()
+ if cli_api_key:
+ env['BROWSER_USE_API_KEY'] = cli_api_key
+
# Start daemon as background process
if sys.platform == 'win32':
subprocess.Popen(