From 1f07d860bf9a3eec30c07ec2f92d80f1cf6e054b Mon Sep 17 00:00:00 2001 From: "haobiao.ning" <774981807@qq.com> Date: Tue, 14 Jul 2026 15:32:09 +0800 Subject: [PATCH] feat: support OPENAI_BASE_URL for the openai provider The `openai` provider had no `baseUrlEnvKey`, so a custom base URL could only reach it implicitly via the OpenAI SDK reading the `OPENAI_BASE_URL` env var. Make this explicit and consistent with the `openai-compatible` and `anthropic` providers: - Add `OPENAI_BASE_URL_ENV_KEY` and wire it as the `openai` provider's `baseUrlEnvKey`, so `resolveProviderBaseUrl("openai")` honors it and the resolved `baseURL` is passed through to the model client. - Register `OPENAI_BASE_URL` in `MANAGED_ENV_KEYS` so it is loaded from `~/.openwiki/.env`, persisted in stable order, and surfaced in the credential diagnostics as a non-secret value (like the other base URL keys). This lets the `openai` provider target an OpenAI-compatible Responses-API gateway (e.g. a Codex-backed proxy) directly from `.env`, instead of forcing users onto the `openai-compatible` provider, which routes tool calls through chat completions and fails on such gateways. Co-Authored-By: Claude Fable 5 --- README.md | 13 +++++++++++++ src/constants.ts | 2 ++ src/env.ts | 3 +++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 69037f62..2d2046b5 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,19 @@ ANTHROPIC_API_KEY=your-key ANTHROPIC_BASE_URL=https://your-gateway.example.com/anthropic ``` +The `openai` provider likewise supports an alternative, OpenAI-compatible +endpoint (for example a self-hosted or proxied gateway) via `OPENAI_BASE_URL`, +set alongside `OPENAI_API_KEY`. This is useful for OpenAI-compatible gateways +that expose the Responses API, since the `openai` provider routes tool calls +through the Responses API (`/v1/responses`) rather than chat completions: + +```bash +OPENWIKI_PROVIDER=openai +OPENAI_API_KEY=your-key +OPENAI_BASE_URL=https://your-gateway.example.com/v1 +OPENWIKI_MODEL_ID=your-model-name +``` + ### OpenAI-compatible endpoints The `openai-compatible` provider targets any OpenAI-compatible chat-completions diff --git a/src/constants.ts b/src/constants.ts index 8e61641e..f44d1012 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,6 +5,7 @@ export const FIREWORKS_API_KEY_ENV_KEY = "FIREWORKS_API_KEY"; export const NEBIUS_API_KEY_ENV_KEY = "NEBIUS_API_KEY"; export const NVIDIA_API_KEY_ENV_KEY = "NVIDIA_API_KEY"; export const OPENAI_API_KEY_ENV_KEY = "OPENAI_API_KEY"; +export const OPENAI_BASE_URL_ENV_KEY = "OPENAI_BASE_URL"; export const OPENAI_COMPATIBLE_API_KEY_ENV_KEY = "OPENAI_COMPATIBLE_API_KEY"; export const OPENAI_COMPATIBLE_BASE_URL_ENV_KEY = "OPENAI_COMPATIBLE_BASE_URL"; export const OPENAI_CHATGPT_ACCESS_TOKEN_ENV_KEY = @@ -237,6 +238,7 @@ export const PROVIDER_CONFIGS: Record = { }, openai: { apiKeyEnvKey: OPENAI_API_KEY_ENV_KEY, + baseUrlEnvKey: OPENAI_BASE_URL_ENV_KEY, label: "OpenAI", modelOptions: OPENAI_MODEL_OPTIONS, }, diff --git a/src/env.ts b/src/env.ts index cd8ff9c9..6995f463 100644 --- a/src/env.ts +++ b/src/env.ts @@ -17,6 +17,7 @@ import { normalizeProvider, NVIDIA_API_KEY_ENV_KEY, OPENAI_API_KEY_ENV_KEY, + OPENAI_BASE_URL_ENV_KEY, OPENAI_CHATGPT_ACCESS_TOKEN_ENV_KEY, OPENAI_CHATGPT_ACCOUNT_ID_ENV_KEY, OPENAI_CHATGPT_EMAIL_ENV_KEY, @@ -83,6 +84,7 @@ export const MANAGED_ENV_KEYS = [ NEBIUS_API_KEY_ENV_KEY, NVIDIA_API_KEY_ENV_KEY, OPENAI_API_KEY_ENV_KEY, + OPENAI_BASE_URL_ENV_KEY, OPENAI_CHATGPT_ACCESS_TOKEN_ENV_KEY, OPENAI_CHATGPT_REFRESH_TOKEN_ENV_KEY, OPENAI_CHATGPT_EXPIRES_AT_ENV_KEY, @@ -280,6 +282,7 @@ function isNonSecretDiagnosticKey(key: string): boolean { key === OPENWIKI_PROVIDER_ENV_KEY || key === OPENWIKI_PROVIDER_RETRY_ATTEMPTS_ENV_KEY || key === ANTHROPIC_BASE_URL_ENV_KEY || + key === OPENAI_BASE_URL_ENV_KEY || key === OPENAI_COMPATIBLE_BASE_URL_ENV_KEY || key === BEDROCK_AWS_REGION_ENV_KEY || key === GOOGLE_CLOUD_PROJECT_ENV_KEY ||