Skip to content

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

fix(vercel): require gateway credentials

MagMuellerfb916aec5600
diff --git a/browser_use/llm/vercel/chat.py b/browser_use/llm/vercel/chat.py
index c10842aed..1d1b4e3af 100644
--- a/browser_use/llm/vercel/chat.py
+++ b/browser_use/llm/vercel/chat.py
@@ -348,6 +348,12 @@ class ChatVercel(BaseChatModel):
def _get_client_params(self) -> dict[str, Any]:
"""Prepare client parameters dictionary."""
api_key = self.api_key or os.getenv('AI_GATEWAY_API_KEY') or os.getenv('VERCEL_OIDC_TOKEN')
+ if not api_key:
+ raise ModelProviderError(
+ message='Missing Vercel AI Gateway API key. Set AI_GATEWAY_API_KEY or VERCEL_OIDC_TOKEN, or pass api_key.',
+ status_code=401,
+ model=self.name,
+ )
base_params = {
'api_key': api_key,
diff --git a/tests/ci/models/test_llm_vercel.py b/tests/ci/models/test_llm_vercel.py
new file mode 100644
index 000000000..5a5af5faf
--- /dev/null
+++ b/tests/ci/models/test_llm_vercel.py
@@ -0,0 +1,18 @@
+"""Regression tests for Vercel AI Gateway client setup."""
+
+import pytest
+
+from browser_use.llm.exceptions import ModelProviderError
+from browser_use.llm.vercel.chat import ChatVercel
+
+
+def test_provider_key_does_not_fall_back_to_openai_key(monkeypatch: pytest.MonkeyPatch):
+ monkeypatch.setenv('OPENAI_API_KEY', 'wrong-provider-key')
+ monkeypatch.setenv('AI_GATEWAY_API_KEY', 'gateway-key')
+ assert ChatVercel(model='openai/gpt-4o').get_client().api_key == 'gateway-key'
+
+ monkeypatch.delenv('AI_GATEWAY_API_KEY')
+ monkeypatch.delenv('VERCEL_OIDC_TOKEN', raising=False)
+ with pytest.raises(ModelProviderError, match='Missing Vercel AI Gateway API key') as exc_info:
+ ChatVercel(model='openai/gpt-4o').get_client()
+ assert exc_info.value.status_code == 401