Skip to content

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

test(llm): cover DeepSeek and Cerebras API key resolution

nina-mir2d86d6f58436
diff --git a/tests/ci/models/test_llm_cerebras.py b/tests/ci/models/test_llm_cerebras.py
new file mode 100644
index 000000000..809d3e21b
--- /dev/null
+++ b/tests/ci/models/test_llm_cerebras.py
@@ -0,0 +1,22 @@
+"""Regression tests for Cerebras client setup."""
+
+import pytest
+
+from browser_use.llm.cerebras.chat import ChatCerebras
+from browser_use.llm.exceptions import ModelProviderError
+
+
+def test_provider_key_does_not_fall_back_to_openai_key(monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.setenv('OPENAI_API_KEY', 'wrong-provider-key')
+ monkeypatch.setenv('CEREBRAS_API_KEY', 'cerebras-key')
+ assert ChatCerebras(model='llama3.3-70b')._client().api_key == 'cerebras-key'
+
+ monkeypatch.delenv('CEREBRAS_API_KEY')
+ with pytest.raises(ModelProviderError, match='Missing Cerebras API key') as exc_info:
+ ChatCerebras(model='llama3.3-70b')._client()
+ assert exc_info.value.status_code == 401
+
+
+def test_explicit_api_key_takes_precedence_over_env(monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.setenv('CEREBRAS_API_KEY', 'env-key')
+ assert ChatCerebras(model='llama3.3-70b', api_key='explicit-key')._client().api_key == 'explicit-key'
diff --git a/tests/ci/models/test_llm_deepseek.py b/tests/ci/models/test_llm_deepseek.py
new file mode 100644
index 000000000..0d402214a
--- /dev/null
+++ b/tests/ci/models/test_llm_deepseek.py
@@ -0,0 +1,22 @@
+"""Regression tests for DeepSeek client setup."""
+
+import pytest
+
+from browser_use.llm.deepseek.chat import ChatDeepSeek
+from browser_use.llm.exceptions import ModelProviderError
+
+
+def test_provider_key_does_not_fall_back_to_openai_key(monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.setenv('OPENAI_API_KEY', 'wrong-provider-key')
+ monkeypatch.setenv('DEEPSEEK_API_KEY', 'deepseek-key')
+ assert ChatDeepSeek(model='deepseek-v4-flash')._client().api_key == 'deepseek-key'
+
+ monkeypatch.delenv('DEEPSEEK_API_KEY')
+ with pytest.raises(ModelProviderError, match='Missing DeepSeek API key') as exc_info:
+ ChatDeepSeek(model='deepseek-v4-flash')._client()
+ assert exc_info.value.status_code == 401
+
+
+def test_explicit_api_key_takes_precedence_over_env(monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.setenv('DEEPSEEK_API_KEY', 'env-key')
+ assert ChatDeepSeek(model='deepseek-v4-flash', api_key='explicit-key')._client().api_key == 'explicit-key'