Skip to content

Hi there! I've made some improvements to how API keys are handled for… #1060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

myelsamyE
Copy link

… different providers in your project.

This update takes care of an issue where the command-line interface wasn't correctly managing API keys for providers other than OpenAI.

Here's a summary of what I did:

  1. Prioritized Provider-Specific Keys: I adjusted the code in codex-cli/src/cli.tsx to first try and get the API key using the specific provider's name. This means that if you've set up an environment variable like <PROVIDER>_API_KEY or configured a key for a specific provider in config.json, that will be used before any logic specific to OpenAI kicks in.

  2. Conditional OpenAI Logic: The existing way of getting OpenAI API keys (by checking ~/.codex/auth.json or asking you for it) will now only happen if the provider you've chosen is 'openai' and I couldn't find a key for it through its direct environment variable or configuration.

  3. Corrected Fallback in config.ts: I've updated utils/config.ts so it no longer mistakenly uses the OPENAI_API_KEY environment variable if a key for a different, specified provider isn't found. The OpenAI key will now only be considered as a fallback if the provider you originally asked for was 'openai'.

  4. Improved Error Messaging: I've refined the error message in cli.tsx that appears when an API key is missing. It will now suggest the correct environment variable name based on the provider you're using (for example, TEST_API_KEY if you're using --provider test, or a configured envKey).

  5. Comprehensive Tests: I've added a new set of tests in codex-cli/tests/config.test.tsx to cover various scenarios for getting API keys. This includes custom providers, known providers from the default list, interaction with config.json, and the order in which keys are checked. These tests help ensure the corrected logic works as expected and will prevent issues in the future.

These changes should ensure that your project correctly uses API keys specified through provider-specific environment variables or configurations, and doesn't incorrectly prompt for or use OpenAI keys when other providers are active.

… different providers in your project.

This update takes care of an issue where the command-line interface wasn't correctly managing API keys for providers other than OpenAI.

Here's a summary of what I did:

1.  **Prioritized Provider-Specific Keys**: I adjusted the code in `codex-cli/src/cli.tsx` to first try and get the API key using the specific provider's name. This means that if you've set up an environment variable like `<PROVIDER>_API_KEY` or configured a key for a specific provider in `config.json`, that will be used before any logic specific to OpenAI kicks in.

2.  **Conditional OpenAI Logic**: The existing way of getting OpenAI API keys (by checking `~/.codex/auth.json` or asking you for it) will now only happen if the provider you've chosen is 'openai' and I couldn't find a key for it through its direct environment variable or configuration.

3.  **Corrected Fallback in `config.ts`**: I've updated `utils/config.ts` so it no longer mistakenly uses the `OPENAI_API_KEY` environment variable if a key for a *different*, specified provider isn't found. The OpenAI key will now only be considered as a fallback if the provider you originally asked for was 'openai'.

4.  **Improved Error Messaging**: I've refined the error message in `cli.tsx` that appears when an API key is missing. It will now suggest the correct environment variable name based on the provider you're using (for example, `TEST_API_KEY` if you're using `--provider test`, or a configured `envKey`).

5.  **Comprehensive Tests**: I've added a new set of tests in `codex-cli/tests/config.test.tsx` to cover various scenarios for getting API keys. This includes custom providers, known providers from the default list, interaction with `config.json`, and the order in which keys are checked. These tests help ensure the corrected logic works as expected and will prevent issues in the future.

These changes should ensure that your project correctly uses API keys specified through provider-specific environment variables or configurations, and doesn't incorrectly prompt for or use OpenAI keys when other providers are active.
Copy link


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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