Skip to content

model_api_key should be configurable #139

@ODAncona

Description

@ODAncona

I would love to use another syntax than MODEL_API_KEY such as OPENAI_API_KEY="sk-proj-xxxxxxxx" like this model_client_options={"apiKey": os.getenv("OPENAI_API_KEY")},

However, the code check that MODEL_API_KEY is defined... Which prevents me to run it.

(cloud-browser-automated-agent) ➜  cloud_browser_automated_agent git:(main) ✗ python main.py
2025-07-07 19:34:27 INFO - model_api_key is recommended when creating a new BROWSERBASE session to configure the Stagehand 
server's LLM.
Traceback (most recent call last):
  File "test/cloud_browser_automated_agent/main.py", line 34, in <module>
    asyncio.run(main())
  File "/home/olivier/.local/share/uv/python/cpython-3.12.10-linux-x86_64-gnu/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/home/olivier/.local/share/uv/python/cpython-3.12.10-linux-x86_64-gnu/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/olivier/.local/share/uv/python/cpython-3.12.10-linux-x86_64-gnu/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "test/cloud_browser_automated_agent/main.py", line 20, in main
    await stagehand.init()
  File "test/cloud_browser_automated_agent/.venv/lib/python3.12/site-packages/stagehand/main.py", line 400, in init
    await self._create_session()  # Uses self._client and api_url
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "test/cloud_browser_automated_agent/.venv/lib/python3.12/site-packages/stagehand/api.py", line 20, in _create_session
    raise ValueError("model_api_key is required to create a session.")
ValueError: model_api_key is required to create a session.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions