Skip to content

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

Resolve Anthropic default LLM names

Magnus Müller9c9fa4d7222e
diff --git a/browser_use/llm/models.py b/browser_use/llm/models.py
index bd38be39d..14d021026 100644
--- a/browser_use/llm/models.py
+++ b/browser_use/llm/models.py
@@ -65,6 +65,10 @@ google_gemini_2_5_pro: 'BaseChatModel'
google_gemini_2_5_flash: 'BaseChatModel'
google_gemini_2_5_flash_lite: 'BaseChatModel'
+anthropic_claude_sonnet_4_0: 'BaseChatModel'
+anthropic_claude_3_5_sonnet_latest: 'BaseChatModel'
+anthropic_claude_3_5_haiku_latest: 'BaseChatModel'
+
cerebras_llama3_1_8b: 'BaseChatModel'
cerebras_llama3_3_70b: 'BaseChatModel'
cerebras_gpt_oss_120b: 'BaseChatModel'
@@ -157,6 +161,13 @@ def get_llm_by_name(model_name: str):
api_key = os.getenv('GOOGLE_API_KEY')
return ChatGoogle(model=model, api_key=api_key)
+ # Anthropic Models
+ elif provider == 'anthropic':
+ from browser_use.llm.anthropic.chat import ChatAnthropic
+
+ api_key = os.getenv('ANTHROPIC_API_KEY')
+ return ChatAnthropic(model=model, api_key=api_key)
+
# OCI Models
elif provider == 'oci':
# OCI requires more complex configuration that can't be easily inferred from env vars
@@ -176,7 +187,7 @@ def get_llm_by_name(model_name: str):
return ChatBrowserUse(model=model, api_key=api_key)
else:
- available_providers = ['openai', 'azure', 'google', 'oci', 'cerebras', 'bu']
+ available_providers = ['openai', 'azure', 'google', 'anthropic', 'oci', 'cerebras', 'bu']
raise ValueError(f"Unknown provider: '{provider}'. Available providers: {', '.join(available_providers)}")
@@ -252,6 +263,10 @@ __all__ += [
'google_gemini_2_5_pro',
'google_gemini_2_5_flash',
'google_gemini_2_5_flash_lite',
+ # Anthropic instances - created on demand
+ 'anthropic_claude_sonnet_4_0',
+ 'anthropic_claude_3_5_sonnet_latest',
+ 'anthropic_claude_3_5_haiku_latest',
# Cerebras instances - created on demand
'cerebras_llama3_1_8b',
'cerebras_llama3_3_70b',
diff --git a/tests/ci/models/test_llm_model_factory.py b/tests/ci/models/test_llm_model_factory.py
new file mode 100644
index 000000000..7643de28d
--- /dev/null
+++ b/tests/ci/models/test_llm_model_factory.py
@@ -0,0 +1,12 @@
+from browser_use.llm.anthropic.chat import ChatAnthropic
+from browser_use.llm.models import get_llm_by_name
+
+
+def test_get_llm_by_name_resolves_anthropic_from_env(monkeypatch):
+ monkeypatch.setenv('ANTHROPIC_API_KEY', 'anthropic-test-key')
+
+ llm = get_llm_by_name('anthropic_claude_sonnet_4_0')
+
+ assert isinstance(llm, ChatAnthropic)
+ assert llm.model == 'claude-sonnet-4-0'
+ assert llm.api_key == 'anthropic-test-key'