Skip to content

fix(openai): honor OPENAI_BASE_URL when no provider config sets a baseUrl#74427

Closed
sunapi386 wants to merge 2 commits into
openclaw:mainfrom
aceteam-ai:fix/openai-base-url-env
Closed

fix(openai): honor OPENAI_BASE_URL when no provider config sets a baseUrl#74427
sunapi386 wants to merge 2 commits into
openclaw:mainfrom
aceteam-ai:fix/openai-base-url-env

Conversation

@sunapi386

Copy link
Copy Markdown

Summary

The dynamic-model resolver in extensions/openai/openai-provider.ts hardcodes baseUrl: \"https://api.openai.com/v1\" for every default GPT entry. This silently overrides OPENAI_BASE_URL, so users running OpenClaw behind a LiteLLM/vLLM/local proxy get a 401 from api.openai.com even when the env var is set correctly — the discovered baseUrl wins via ?? discoveredModel.baseUrl in src/agents/pi-embedded-runner/model.ts:530.

The fix introduces resolveOpenAIDefaultBaseUrl() in extensions/openai/base-url.ts that returns process.env.OPENAI_BASE_URL (when non-empty) and falls back to https://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_URL when baseURL is undefined.

Backwards compatibility

Provider-config baseUrl still takes precedence (the resolver consults providerConfig.baseUrl before discoveredModel.baseUrl at model.ts:530):

User has Before After
Nothing (default) api.openai.com api.openai.com (unchanged)
models.providers.openai.baseUrl in config their config their config (unchanged)
Only OPENAI_BASE_URL env var api.openai.com (silent ignore) env var honored
Both env var and config config config (unchanged)

No 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:474 rather 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

  • Added unit coverage in extensions/openai/base-url.test.ts (env unset, empty, whitespace, custom URL).
  • pnpm test -- extensions/openai/base-url.test.ts passes (6 tests).
  • CI run on upstream main.

@clawsweeper

clawsweeper Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed May 30, 2026, 12:52 AM ET / 04:52 UTC.

Summary
Review failed before ClawSweeper could summarize the requested change.

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: 🌊 off-meta tidepool
Proof: 🌊 off-meta tidepool
Patch quality: 🌊 off-meta tidepool
Result: rating does not apply to this item.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] No close action taken because the review did not complete.

Maintainer options:

  1. Decide the mitigation before merge
    Retry the Codex review after fixing the execution failure.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] Review did not complete, so no work-lane recommendation was made.
Review details

Best 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 changes

Label changes:

  • add rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.

Label justifications:

  • rating: 🌊 off-meta tidepool: Overall readiness is 🌊 off-meta tidepool; proof is 🌊 off-meta tidepool and patch quality is 🌊 off-meta tidepool.
Evidence reviewed

PR surface:

Source +16, Tests +11, Docs +1. Total +28 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 22 6 +16
Tests 1 11 0 +11
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 34 6 +28

What I checked:

  • failure reason: codex execution failed.
  • codex failure detail: Codex review failed for this PR with exit 1.
  • codex stdout: Per-item Codex failure; continuing with the rest of the shard.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

sunapi386 and others added 2 commits May 13, 2026 11:49
…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>
@sunapi386 sunapi386 force-pushed the fix/openai-base-url-env branch from a9867dd to c8e3224 Compare May 13, 2026 15:51
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 13, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label May 30, 2026
@clawsweeper clawsweeper Bot added the rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. label May 30, 2026
@barnacle-openclaw barnacle-openclaw Bot removed the stale Marked as stale due to inactivity label May 30, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. labels May 30, 2026
steipete added a commit that referenced this pull request Jun 2, 2026
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.
@steipete

steipete commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR. I landed the current-source version of this fix in #89347 / commit 732d697, with exact-head CI and focused provider/model proof recorded there.

Closing this as superseded by the merged maintainer batch.

@steipete steipete closed this Jun 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 3, 2026
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.
SYU8384 pushed a commit to SYU8384/openclaw that referenced this pull request Jun 3, 2026
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.
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: openai merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants