Skip to content

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

added required env variables mapping + check env func in utils

Anish Hiranandanic2332f0e9691
diff --git a/browser_use/constants.py b/browser_use/constants.py
new file mode 100644
index 000000000..670b1b03f
--- /dev/null
+++ b/browser_use/constants.py
@@ -0,0 +1,7 @@
+REQUIRED_ENV_VARIABLES = {
+ "ChatOpenAI": ["OPENAI_API_KEY"],
+ "AzureOpenAI": ["AZURE_ENDPOINT", "AZURE_OPENAI_API_KEY"],
+ "ChatBedrockConverse": ["ANTHROPIC_API_KEY"],
+ "ChatAnthropic": ["ANTHROPIC_API_KEY"],
+ "ChatGoogleGenerativeAI": ["GEMINI_API_KEY"]
+}
\ No newline at end of file
diff --git a/browser_use/utils.py b/browser_use/utils.py
index 860b35a32..d232b0aa6 100644
--- a/browser_use/utils.py
+++ b/browser_use/utils.py
@@ -2,6 +2,7 @@ import logging
import time
from functools import wraps
from typing import Any, Callable, Coroutine, ParamSpec, TypeVar
+import os
logger = logging.getLogger(__name__)
@@ -52,3 +53,8 @@ def singleton(cls):
return instance[0]
return wrapper
+
+
+def check_env_variables(keys: list[str], any_or_all=all) -> bool:
+ """ Check if all required environment variables are set """
+ return any_or_all(os.getenv(key).strip() for key in keys)
\ No newline at end of file