Skip to content

fix: 400 error when using other providers after logging into OpenAI #1296

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

Dcatfly
Copy link

@Dcatfly Dcatfly commented Jun 10, 2025

If the user is logged into openai, i.e., the ~/.codex/auth.json file exists, and the user switches to other providers, the openai key is still used, which will cause a request error. Related issues: #987

bug image

This modification mainly includes the following points:

  1. Fix the logic of reading the key, and change it to reading the key based on the provider
  2. When ~/.codex/auth.json does not exist:
  • Currently: Regardless of the current provider, whether the corresponding key exists in the env, it will display "Login to ChatGPT" and "Enter OpenAI key".
  • After the change:
    • If the current provider is OpenAI, it will display 1) Login to ChatGPT 2) Manually enter OpenAI key.
    • If the current provider is not OpenAI
      • If the key corresponding to the provider exists in the env, it is used directly.
      • If it does not exist in the env, only manually enter provider key.
  1. Optimized the logic for obtaining savedTokens, abstracting it into the loadAuth method.
  2. Optimized the assignment logic for process.env["OPENAI_API_KEY"] to prioritize fetching the value from process.env; if it's not there, it will fetch from auth.json.

Copy link

github-actions bot commented Jun 10, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Dcatfly
Copy link
Author

Dcatfly commented Jun 10, 2025

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

github-actions bot added a commit that referenced this pull request Jun 10, 2025
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