Skip to content

fix(providers): treat an empty OpenAI api_key as unset - #41

Merged
zhanghanduo merged 2 commits into
mainfrom
fix/openai-empty-api-key
Sep 25, 2026
Merged

zhanghanduo merged 2 commits into
mainfrom
fix/openai-empty-api-key

Conversation

@zhanghanduo

Copy link
Copy Markdown
Collaborator

Summary

OpenAIClient and OpenAIResponsesClient passed api_key straight to AsyncOpenAI. The SDK only consults OPENAI_API_KEY when api_key is None; an empty string raises OpenAIError: Missing credentials even when the env var is set (verified on openai 3.7.0). Host configs read before the environment is populated legitimately hold "", so both clients now pass api_key or None.

Found while migrating FrontierAgent onto AgentCore 0.11.1 — its forked client already did api_key or None, and it currently carries a subclass just to keep that behaviour (ApodexAI/FrontierAgent#50).

Changelog entry (suggested, under Fixed)

  • OpenAIClient / OpenAIResponsesClient: an empty api_key now falls back to OPENAI_API_KEY like None, instead of raising "Missing credentials".

Test plan

  • New tests/test_openai_empty_api_key.py (fails without the fix, passes with it)
  • ruff, pyright agent_core, full pytest -q

🤖 Generated with Claude Code

zhanghanduo and others added 2 commits September 25, 2026 13:24
The OpenAI SDK falls back to OPENAI_API_KEY only when api_key is None; an
empty string raises "Missing credentials" even with the variable set. A
host config read before the environment is populated legitimately holds
"", so both OpenAI clients now pass api_key or None.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@zhanghanduo
zhanghanduo merged commit 171d82a into main Sep 25, 2026
5 checks passed
@zhanghanduo
zhanghanduo deleted the fix/openai-empty-api-key branch September 25, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant