diff --git a/README.md b/README.md index ab4701bf..32a73bdc 100644 --- a/README.md +++ b/README.md @@ -97,12 +97,19 @@ export OPENAI_API_KEY="your-api-key-here" > - deepseek > - xai > - groq +> - any other provider that is compatible with the OpenAI API > > If you use a provider other than OpenAI, you will need to set the API key for the provider in the config file or in the environment variable as: > > ```shell > export _API_KEY="your-api-key-here" > ``` +> +> If you use a provider not listed above, you must also set the base URL for the provider: +> +> ```shell +> export _BASE_URL="https://your-provider-api-base-url" +> ```
diff --git a/codex-cli/src/utils/config.ts b/codex-cli/src/utils/config.ts index 1df2e197..7085b6fc 100644 --- a/codex-cli/src/utils/config.ts +++ b/codex-cli/src/utils/config.ts @@ -76,6 +76,12 @@ export function getApiKey(provider: string = "openai"): string | undefined { return process.env[providerInfo.envKey]; } + // Checking `PROVIDER_API_KEY feels more intuitive with a custom provider. + const customApiKey = process.env[`${provider.toUpperCase()}_API_KEY`]; + if (customApiKey) { + return customApiKey; + } + // If the provider not found in the providers list and `OPENAI_API_KEY` is set, use it if (OPENAI_API_KEY !== "") { return OPENAI_API_KEY;