@@ -23,7 +23,7 @@ def test_init_with_direct_params(self):
23
23
browserbase_session_id = "test-session" ,
24
24
api_key = "test-api-key" ,
25
25
project_id = "test-project-id" ,
26
- model_api_key = " test-model-api-key" ,
26
+ model_client_options = { "apiKey" : " test-model-api-key"} ,
27
27
verbose = 2 ,
28
28
)
29
29
@@ -203,3 +203,32 @@ async def mock_create_session():
203
203
# Call _create_session and expect error
204
204
with pytest .raises (RuntimeError , match = "Invalid response format" ):
205
205
await client ._create_session ()
206
+
207
+ @mock .patch .dict (os .environ , {"MODEL_API_KEY" : "test-model-api-key" }, clear = True )
208
+ def test_init_with_model_api_key_in_env (self ):
209
+ config = StagehandConfig (env = "LOCAL" )
210
+ client = Stagehand (config = config )
211
+ assert client .model_api_key == "test-model-api-key"
212
+
213
+ def test_init_with_custom_llm (self ):
214
+ config = StagehandConfig (
215
+ env = "LOCAL" ,
216
+ model_client_options = {"apiKey" : "custom-llm-key" , "baseURL" : "https://custom-llm.com" }
217
+ )
218
+ client = Stagehand (config = config )
219
+ assert client .model_api_key == "custom-llm-key"
220
+ assert client .model_client_options ["apiKey" ] == "custom-llm-key"
221
+ assert client .model_client_options ["baseURL" ] == "https://custom-llm.com"
222
+
223
+ def test_init_with_custom_llm_override (self ):
224
+ config = StagehandConfig (
225
+ env = "LOCAL" ,
226
+ model_client_options = {"apiKey" : "custom-llm-key" , "baseURL" : "https://custom-llm.com" }
227
+ )
228
+ client = Stagehand (
229
+ config = config ,
230
+ model_client_options = {"apiKey" : "override-llm-key" , "baseURL" : "https://override-llm.com" }
231
+ )
232
+ assert client .model_api_key == "override-llm-key"
233
+ assert client .model_client_options ["apiKey" ] == "override-llm-key"
234
+ assert client .model_client_options ["baseURL" ] == "https://override-llm.com"
0 commit comments