Skip to content

Commit 9ffaef3

Browse files
committed
MODEL_API_KEY is the public facing env, but either MODEL_API_KEY or OPENAI_API_KEY can be used - one is required to be set.
1 parent 5a81a55 commit 9ffaef3

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

examples/local_example.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
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
1112
Install the published wheel before running this script:
1213
`pip install stagehand-alpha`
@@ -22,13 +23,15 @@
2223

2324

2425
def 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

test_local_mode.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
from 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

1818
print("🚀 Testing local server mode...") # noqa: T201
@@ -24,7 +24,7 @@
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

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)