@@ -228,3 +228,32 @@ async def mock_create_session():
228228 # Call _create_session and expect error
229229 with pytest .raises (RuntimeError , match = "Invalid response format" ):
230230 await client ._create_session ()
231+
232+ @mock .patch .dict (os .environ , {"MODEL_API_KEY" : "test-model-api-key" }, clear = True )
233+ def test_init_with_model_api_key_in_env (self ):
234+ config = StagehandConfig (env = "LOCAL" )
235+ client = Stagehand (config = config )
236+ assert client .model_api_key == "test-model-api-key"
237+
238+ def test_init_with_custom_llm (self ):
239+ config = StagehandConfig (
240+ env = "LOCAL" ,
241+ model_client_options = {"apiKey" : "custom-llm-key" , "baseURL" : "https://custom-llm.com" }
242+ )
243+ client = Stagehand (config = config )
244+ assert client .model_api_key == "custom-llm-key"
245+ assert client .model_client_options ["apiKey" ] == "custom-llm-key"
246+ assert client .model_client_options ["baseURL" ] == "https://custom-llm.com"
247+
248+ def test_init_with_custom_llm_override (self ):
249+ config = StagehandConfig (
250+ env = "LOCAL" ,
251+ model_client_options = {"apiKey" : "custom-llm-key" , "baseURL" : "https://custom-llm.com" }
252+ )
253+ client = Stagehand (
254+ config = config ,
255+ model_client_options = {"apiKey" : "override-llm-key" , "baseURL" : "https://override-llm.com" }
256+ )
257+ assert client .model_api_key == "override-llm-key"
258+ assert client .model_client_options ["apiKey" ] == "override-llm-key"
259+ assert client .model_client_options ["baseURL" ] == "https://override-llm.com"
0 commit comments