fix(openai): honor OPENAI_BASE_URL when no provider config sets a baseUrl#74427
fix(openai): honor OPENAI_BASE_URL when no provider config sets a baseUrl#74427sunapi386 wants to merge 2 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed May 30, 2026, 12:52 AM ET / 04:52 UTC. Summary PR surface: Source +16, Tests +11, Docs +1. Total +28 across 4 files. Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path. Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Review detailsBest possible solution: Retry the Codex review after fixing the execution failure. Do we have a high-confidence way to reproduce the issue? Unclear. The review failed before ClawSweeper could establish a reproduction path. Is this the best way to solve the issue? Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model gpt-5.5, reasoning high; reviewed against b9933b2ec119. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +16, Tests +11, Docs +1. Total +28 across 4 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
…eUrl The dynamic-model resolver in extensions/openai/openai-provider.ts hardcoded `baseUrl: "https://api.openai.com/v1"` for every default GPT entry. This means setting `OPENAI_BASE_URL` in env (e.g. when running OpenClaw behind a LiteLLM/vLLM/local-proxy) has no effect — the discovered baseUrl wins via the `?? discoveredModel.baseUrl` fallback in src/agents/pi-embedded-runner/model.ts and the agent calls api.openai.com directly with a stale or proxy-style key, returning 401. Adds `resolveOpenAIDefaultBaseUrl()` in base-url.ts that returns `process.env.OPENAI_BASE_URL` (when non-empty) and falls back to the hardcoded URL otherwise. Replaces the 5 hardcoded literals in the dynamic model registry with the helper. This mirrors the precedent set by openclaw#55597 (honor OPENAI_BASE_URL in whisper api skill) and matches what the OpenAI Node SDK already does — its constructor falls back to env when `baseURL` is undefined. Provider-config baseUrl still takes precedence (resolver consults `providerConfig.baseUrl` before `discoveredModel.baseUrl`), so this is fully backwards-compatible: users with explicit config see no change, users with only the env var now get the routing they expected.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
a9867dd to
c8e3224
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
Repairs a batch of narrow model/provider edge cases: - honor OpenAI and Anthropic base URL environment overrides when provider config does not set an explicit base URL - preserve OpenRouter Anthropic cache retention while stripping unsupported transport options - allow apply_patch for non-OpenAI providers when the tool config otherwise permits it - prune stale same-provider model selections from configure/model picker state - expose GitHub Copilot bundled thinking policy metadata to offline/provider-policy lookups - repair additive SQLite shared-state upgrades for existing databases - keep same-size rotated log readers from reusing stale content in CI tooling Proof: - GitHub PR checks green on exact head 4651490 - Crabbox delegated Blacksmith Testbox tbx_01kt3em5r9vd7g0bnykrff6jdk exited 0 - Focused local Vitest/oxlint/format proof recorded in PR body and land-ready comment Fixes #80347. Fixes #88357. Fixes #45269. Supersedes #74427, #74432, #79370, #79894, #80366, and #88359.
Repairs a batch of narrow model/provider edge cases: - honor OpenAI and Anthropic base URL environment overrides when provider config does not set an explicit base URL - preserve OpenRouter Anthropic cache retention while stripping unsupported transport options - allow apply_patch for non-OpenAI providers when the tool config otherwise permits it - prune stale same-provider model selections from configure/model picker state - expose GitHub Copilot bundled thinking policy metadata to offline/provider-policy lookups - repair additive SQLite shared-state upgrades for existing databases - keep same-size rotated log readers from reusing stale content in CI tooling Proof: - GitHub PR checks green on exact head 4651490 - Crabbox delegated Blacksmith Testbox tbx_01kt3em5r9vd7g0bnykrff6jdk exited 0 - Focused local Vitest/oxlint/format proof recorded in PR body and land-ready comment Fixes openclaw#80347. Fixes openclaw#88357. Fixes openclaw#45269. Supersedes openclaw#74427, openclaw#74432, openclaw#79370, openclaw#79894, openclaw#80366, and openclaw#88359.
Repairs a batch of narrow model/provider edge cases: - honor OpenAI and Anthropic base URL environment overrides when provider config does not set an explicit base URL - preserve OpenRouter Anthropic cache retention while stripping unsupported transport options - allow apply_patch for non-OpenAI providers when the tool config otherwise permits it - prune stale same-provider model selections from configure/model picker state - expose GitHub Copilot bundled thinking policy metadata to offline/provider-policy lookups - repair additive SQLite shared-state upgrades for existing databases - keep same-size rotated log readers from reusing stale content in CI tooling Proof: - GitHub PR checks green on exact head 4651490 - Crabbox delegated Blacksmith Testbox tbx_01kt3em5r9vd7g0bnykrff6jdk exited 0 - Focused local Vitest/oxlint/format proof recorded in PR body and land-ready comment Fixes openclaw#80347. Fixes openclaw#88357. Fixes openclaw#45269. Supersedes openclaw#74427, openclaw#74432, openclaw#79370, openclaw#79894, openclaw#80366, and openclaw#88359.
Repairs a batch of narrow model/provider edge cases: - honor OpenAI and Anthropic base URL environment overrides when provider config does not set an explicit base URL - preserve OpenRouter Anthropic cache retention while stripping unsupported transport options - allow apply_patch for non-OpenAI providers when the tool config otherwise permits it - prune stale same-provider model selections from configure/model picker state - expose GitHub Copilot bundled thinking policy metadata to offline/provider-policy lookups - repair additive SQLite shared-state upgrades for existing databases - keep same-size rotated log readers from reusing stale content in CI tooling Proof: - GitHub PR checks green on exact head 4651490 - Crabbox delegated Blacksmith Testbox tbx_01kt3em5r9vd7g0bnykrff6jdk exited 0 - Focused local Vitest/oxlint/format proof recorded in PR body and land-ready comment Fixes openclaw#80347. Fixes openclaw#88357. Fixes openclaw#45269. Supersedes openclaw#74427, openclaw#74432, openclaw#79370, openclaw#79894, openclaw#80366, and openclaw#88359.
Summary
The dynamic-model resolver in
extensions/openai/openai-provider.tshardcodesbaseUrl: \"https://api.openai.com/v1\"for every default GPT entry. This silently overridesOPENAI_BASE_URL, so users running OpenClaw behind a LiteLLM/vLLM/local proxy get a 401 fromapi.openai.comeven when the env var is set correctly — the discovered baseUrl wins via?? discoveredModel.baseUrlinsrc/agents/pi-embedded-runner/model.ts:530.The fix introduces
resolveOpenAIDefaultBaseUrl()inextensions/openai/base-url.tsthat returnsprocess.env.OPENAI_BASE_URL(when non-empty) and falls back tohttps://api.openai.com/v1. The 5 hardcoded literals in the registry are replaced with the helper.This mirrors the precedent of #55597 ("honor OPENAI_BASE_URL in whisper api skill") and matches what the OpenAI Node SDK already does — its constructor falls back to
process.env.OPENAI_BASE_URLwhenbaseURLisundefined.Backwards compatibility
Provider-config baseUrl still takes precedence (the resolver consults
providerConfig.baseUrlbeforediscoveredModel.baseUrlatmodel.ts:530):models.providers.openai.baseUrlin configOPENAI_BASE_URLenv varNo existing user is broken. Users who set the env var expecting it to work — like the OpenAI Node SDK's own behavior — now get the routing they expected.
Why not anthropic too
Anthropic's hardcoded fallback is in
src/agents/anthropic-transport-stream.ts:474rather than a model registry, and the discovery flow is shaped differently. Keeping this PR scoped to OpenAI to mirror the #55597 precedent and make review easy. Happy to follow up with an analogous Anthropic PR if this lands.Test plan
extensions/openai/base-url.test.ts(env unset, empty, whitespace, custom URL).pnpm test -- extensions/openai/base-url.test.tspasses (6 tests).