File tree Expand file tree Collapse file tree 3 files changed +12
-9
lines changed
Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Original file line number Diff line number Diff line change 66- BROWSERBASE_API_KEY (can be any value in local mode)
77- BROWSERBASE_PROJECT_ID (can be any value in local mode)
88- MODEL_API_KEY (used for client configuration even in local mode)
9- - OPENAI_API_KEY (used by the SEA server for LLM access)
9+
10+ You can also set `OPENAI_API_KEY` if you prefer, but the example defaults to `MODEL_API_KEY`.
1011
1112Install the published wheel before running this script:
1213 `pip install stagehand-alpha`
2223
2324
2425def main () -> None :
26+ model_key = os .environ .get ("MODEL_API_KEY" )
2527 openai_key = os .environ .get ("OPENAI_API_KEY" )
26- if not openai_key :
27- sys .exit ("Set the OPENAI_API_KEY environment variable to run the local server." )
28+
29+ if not model_key and not openai_key :
30+ sys .exit ("Set MODEL_API_KEY to run the local server." )
2831
2932 client = Stagehand (
3033 server = "local" ,
31- local_openai_api_key = openai_key ,
34+ local_openai_api_key = openai_key or model_key ,
3235 local_ready_timeout_s = 30.0 ,
3336 )
3437
Original file line number Diff line number Diff line change 1010from stagehand import Stagehand
1111
1212# Set required API key for LLM operations
13- if not os .environ .get ("OPENAI_API_KEY" ):
14- print ("❌ Error: OPENAI_API_KEY environment variable not set" ) # noqa: T201
15- print (" Set it with: export OPENAI_API_KEY ='sk-proj-...'" ) # noqa: T201
13+ if not os .environ .get ("MODEL_API_KEY" ) and not os . environ . get ( " OPENAI_API_KEY" ):
14+ print ("❌ Error: MODEL_API_KEY or OPENAI_API_KEY environment variable not set" ) # noqa: T201
15+ print (" Set it with: export MODEL_API_KEY ='sk-proj-...'" ) # noqa: T201
1616 sys .exit (1 )
1717
1818print ("🚀 Testing local server mode..." ) # noqa: T201
2424 server = "local" ,
2525 browserbase_api_key = "local" , # Dummy value - not used in local mode
2626 browserbase_project_id = "local" , # Dummy value - not used in local mode
27- model_api_key = os .environ ["OPENAI_API_KEY" ],
27+ model_api_key = os .environ . get ( "MODEL_API_KEY" ) or os . environ ["OPENAI_API_KEY" ],
2828 local_headless = True ,
2929 local_port = 0 , # Auto-pick free port
3030 local_ready_timeout_s = 15.0 , # Give it time to start
You can’t perform that action at this time.
0 commit comments