Bug: Quiet mode requires OPENAI_API_KEY even when using other providers
Bug Description
When using non-OpenAI providers (such as OpenRouter), the CLI’s quiet mode (-q) still requires the OPENAI_API_KEY to be set, even though it is not needed.
Steps to Reproduce
- Set the API key for a non-OpenAI provider (e.g.,
OPENROUTER_API_KEY). - Run the CLI in quiet mode with that provider:
````
codex -q --provider openrouter --model anthropic/claude-3.7-sonnet "some prompt"
Current Behavior
The CLI throws an error:
qt [Error]: Missing or unset OPENAI_API_KEY environment variable; please provide it, or instantiate the OpenAI client with the apiKey option, e.g., new OpenAI({ apiKey: 'My API Key' }).
Expected Behavior
When using a specific provider, the CLI should work correctly with only that provider’s API key (e.g., OPENROUTER_API_KEY).
Root Cause
In agent-loop.ts, the code always uses the OpenAI client library, which hardcodes a check for OPENAI_API_KEY during initialization, even when other providers are used. This check occurs before the actual API key and base URL for the specific provider are set.
Temporary Workaround
Currently, users need to set both their provider’s API key and OPENAI_API_KEY (which can be set to the same value) for quiet mode to work with other providers.
Suggested Fixes
- Modify OpenAI client initialization to skip the environment variable check.
- Create provider-specific client implementations that do not depend on the OpenAI client library.
- Add a check to temporarily copy the provider’s API key to
OPENAI_API_KEYduring quiet mode execution.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗