Skip to content

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

Creating a reusable client

Will Bonde62f7d96bbbf6
diff --git a/browser_use/llm/openrouter/chat.py b/browser_use/llm/openrouter/chat.py
index 871fe007e..0fd9a5269 100644
--- a/browser_use/llm/openrouter/chat.py
+++ b/browser_use/llm/openrouter/chat.py
@@ -77,8 +77,10 @@ class ChatOpenRouter(BaseChatModel):
Returns:
AsyncOpenAI: An instance of the AsyncOpenAI client with OpenRouter base URL.
"""
- client_params = self._get_client_params()
- return AsyncOpenAI(**client_params)
+ if not hasattr(self, '_client'):
+ client_params = self._get_client_params()
+ self._client = AsyncOpenAI(**client_params)
+ return self._client
@property
def name(self) -> str: