Skip to content

Commit 610dbf1

Browse files
committed
feat: support both api_key and apiKey for CUA agent API keys
1 parent 0ec5197 commit 610dbf1

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

stagehand/agent/anthropic_cua.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ def __init__(
5858
):
5959
super().__init__(model, instructions, config, logger, handler)
6060
self.experimental = experimental
61-
self.anthropic_sdk_client = Anthropic(
62-
api_key=config.options.get("apiKey") or os.getenv("ANTHROPIC_API_KEY")
63-
)
61+
api_key = None
62+
if config and hasattr(config, 'options') and config.options:
63+
api_key = config.options.get('api_key') or config.options.get('apiKey')
64+
if not api_key:
65+
api_key = os.getenv('ANTHROPIC_API_KEY')
66+
self.anthropic_sdk_client = Anthropic(api_key=api_key)
6467

6568
dimensions = (
6669
(viewport["width"], viewport["height"]) if viewport else (1288, 711)

stagehand/agent/google_cua.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(
4646
# Match OpenAI pattern for API key handling
4747
api_key = None
4848
if config and hasattr(config, "options") and config.options:
49-
api_key = config.options.get("apiKey")
49+
api_key = config.options.get("api_key") or config.options.get("apiKey")
5050
if not api_key:
5151
api_key = os.getenv("GEMINI_API_KEY")
5252
if not api_key:

stagehand/agent/openai_cua.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ def __init__(
4040
):
4141
super().__init__(model, instructions, config, logger, handler)
4242
# TODO pass api key
43-
self.openai_sdk_client = OpenAISDK(
44-
api_key=config.options.get("apiKey") or os.getenv("OPENAI_API_KEY")
45-
)
43+
api_key = None
44+
if config and hasattr(config, 'options') and config.options:
45+
api_key = config.options.get('api_key') or config.options.get('apiKey')
46+
if not api_key:
47+
api_key = os.getenv('OPENAI_API_KEY')
48+
self.openai_sdk_client = OpenAISDK(api_key=api_key)
4649

4750
dimensions = (
4851
(viewport["width"], viewport["height"]) if viewport else (1288, 711)

0 commit comments

Comments
 (0)