Skip to content

fix(ai): send OpenAI and Anthropic requests to their base URL variables on every path - #21244

Open
sjawhar wants to merge 1 commit into
can1357:mainfrom
cybermonklabs:upstream/fix-vendor-base-url-env
Open

sjawhar wants to merge 1 commit into
can1357:mainfrom
cybermonklabs:upstream/fix-vendor-base-url-env

Conversation

@sjawhar

@sjawhar sjawhar commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

What

my agents found this while optimizing our fleet

OPENAI_BASE_URL and ANTHROPIC_BASE_URL now replace the vendor address on every request that sends the vendor key for a built-in openai or anthropic model. Before, ANTHROPIC_BASE_URL moved only Anthropic chat, and OPENAI_BASE_URL moved no request of a built-in openai model, because every built-in row carries https://api.openai.com/v1 and the variable was read only when a model had no address.

One resolver for each vendor, in packages/catalog/src/compat/vendor-base-url.ts, reads the variables. A provider-file baseUrl other than the vendor's own address still wins, as with XAI_BASE_URL. A built-in openai model under the variable is built again at that address, so its request is the request a provider-file baseUrl with that value gets: no stateful Responses chaining by default, and no file upload. Discovered rows keep the built-in address, so the model cache stays valid after the variable is unset.

In Foundry mode (CLAUDE_CODE_USE_FOUNDRY with FOUNDRY_BASE_URL), Anthropic model discovery and web search now follow FOUNDRY_BASE_URL with the client certificate of CLAUDE_CODE_CLIENT_CERT and CLAUDE_CODE_CLIENT_KEY, as chat already did. File upload stays off there.

Each of these paths now also trusts the CA in NODE_EXTRA_CA_CERTS, as chat does, when its caller gives no fetch of its own: it falls back to the wrapFetchForExtraCa shim of pi-utils, not to Bun's own fetch. The image tool no longer hands Bun's fetch down, so each image client falls back as before and hosted image generation takes the shim. A gateway behind a private CA then works on every path, not only on chat.

Why

With either variable set, requests that send the key went to the vendor's host: Responses (HTTP and WebSocket), Chat Completions, model discovery, web search, remote compaction, hosted image generation, embeddings, transcription and the Decisions judge for openai; discovery and web search for anthropic. A gateway's key then reached api.openai.com or api.anthropic.com.

A provider-file baseUrl already moves each of these paths, but nothing a user configures makes web search, compaction, the judge, image generation, embeddings or transcription carry Foundry's client certificate or trust the NODE_EXTRA_CA_CERTS CA. For ANTHROPIC_BASE_URL and Foundry mode this is a fix: chat already follows them. For OPENAI_BASE_URL it is a change of meaning: the docs called it a fallback for a model with no address, and it now replaces the vendor address, as XAI_BASE_URL does. A user who exports OPENAI_BASE_URL for another tool now also sends the requests of omp's built-in openai models there. If you would rather keep the old meaning for OPENAI_BASE_URL, say so and that half comes out of this pull request.

Testing

Two new test files hold the change: packages/coding-agent/test/vendor-base-url-paths.test.ts (one row for each path and state: the variable set, unset, a provider-file baseUrl of another address, a provider-file baseUrl of the vendor's own address, Foundry mode, and NODE_EXTRA_CA_CERTS) and packages/ai/test/openai-vendor-base-url-flags.test.ts (the official-endpoint flags and Responses chaining).

  • Red on main at 9b5b470, with no source change: 53 of the 99 path rows fail on their assertions (each request goes to api.openai.com or api.anthropic.com, or sends without the CA), the WebSocket row among them, and 4 of the 5 flag rows fail. No row fails on an import.
  • Green with this commit: 99 of 99 and 5 of 5. The existing tests of each changed path pass too (provider-fetch-override, openai-compat-user-agent, openai-responses-websocket, image-input-validation, auth-gateway-embeddings and -transcriptions, judgment, connection-prewarm, anthropic-server-compaction, anthropic-oauth, anthropic-alignment, model-registry, model-registry-composed-catalog, model-discovery, web search for both vendors, provider-files, images-cli, the image tool, remote-compaction, anthropic-native-compaction, anthropic-discovery, provider-cache-id).
  • The CLI, from source, against a local listener with both variables set: Responses over HTTP and over WebSocket, Chat Completions, Anthropic Messages, model discovery, both web searches and compaction each reached the listener with the key, and an HTTPS proxy recorder saw no CONNECT to api.openai.com or api.anthropic.com. With the variables deleted, chat goes to api.openai.com again.
  • The whole suite, on main at 9b5b470 and with this commit, once plain and once with OPENAI_BASE_URL, ANTHROPIC_BASE_URL, FOUNDRY_BASE_URL and CLAUDE_CODE_USE_FOUNDRY exported: type checks, lint and format pass in every package, and no test fails with this commit that passes on main, except one run of ImageDescriptions > describes the newest images first… in test/utils/image-vision-fallback.test.ts. This change does not touch that file, and the test passed in nine of ten runs of the file alone. The existing tests that this change would break for a developer with the variables exported now clear them before each test, through one helper in each package's test helpers.

  • bun check passes: bun run check:ts (lint, format and the type checks of every package) passes with this commit. The change touches no Rust file, so the Rust half does not run.
  • Tested locally
  • CHANGELOG updated with the required attribution (if user-facing; internal issue fixes use issue links, external contributions add the PR link and contributor credit after creation)

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-01T06:58:53.733539Z
We couldn’t complete this review. Comment @codex review to try again.
2e347d6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@roboomp roboomp added fix provider:openai Provider-specific issues for openai providers LLM provider-specific issues review:p2 triaged labels Dec 1, 2026

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sjawhar for the thorough path inventory and the red/green test matrix. review:p2: needs a maintainer call.

  • The ANTHROPIC_BASE_URL/Foundry half is a real fix. Discovery and web search now go where chat already goes, and Foundry mTLS is applied to them too. resolveDirectAnthropicBaseUrl keeps the same precedence it had before.
  • The OPENAI_BASE_URL half changes what an existing variable means: it was a fallback for models with no address and now overrides api.openai.com for every built-in openai request. Users who already export it for other tools will silently send omp's OpenAI key to that host. Maintainer: keep it, or drop that half as the PR offers?
  • Should-fix: no CHANGELOG entries in any of the 5 touched packages, and readPemValue duplicates resolveExtraCa in tls-fetch.ts. Scope: the NODE_EXTRA_CA_CERTS shim on every path is a separate behavior change and could land on its own.

| Variable | Default / behavior |
| ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `OPENAI_BASE_URL` | Base URL fallback for OpenAI-compatible requests when the model/provider supplies a default |
| `OPENAI_BASE_URL` | Replaces `https://api.openai.com/v1` on each request of a built-in `openai` model (chat, compaction, model discovery, web search, embeddings, transcription, image generation, judgments). The request is the same as the request for a provider-file `baseUrl` with this value. A provider-file `baseUrl` that is not `https://api.openai.com/v1` wins. The paths that work only with OpenAI's own service stay off: file upload, and stateful Responses chaining by default. Also the fallback address of an OpenAI-compatible model that has no address. `openai-codex` keeps its own address |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer call (default-behavior change). Before this PR OPENAI_BASE_URL was read only in resolveOpenAIRequestSetup when a model had no baseUrl, so it never moved a built-in openai row. Now resolveOpenAIVendorBaseUrl (packages/catalog/src/compat/vendor-base-url.ts:72-79) replaces https://api.openai.com/v1 everywhere, including an explicit provider-file baseUrl: https://api.openai.com/v1. A user who exports OPENAI_BASE_URL for the OpenAI SDK or another tool (common in shell rc files) will start sending omp's OPENAI_API_KEY and traffic to that host, and lose stateful Responses chaining and file upload, with no opt-in. The ANTHROPIC_BASE_URL/Foundry half matches chat's existing behavior; this half needs explicit sign-off, or should be split out as the PR body offers.

* A path that does not exist throws {@link PemPathError}; other I/O errors
* bubble.
*/
export function readPemValue(value: string | undefined, name: string): string | undefined {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix (duplication). readPemValue re-implements resolveExtraCa (line 85) in the same file: same inline-vs-path detection, same \\n expansion, same ENOENT mapping, but a different error class (PemPathError vs ExtraCaError) and a separate cache (pemValueCacheKey vs cacheKey). After this PR NODE_EXTRA_CA_CERTS is read by readPemValue in anthropic-http-options.ts (Foundry chat) and by resolveExtraCa on every path that now goes through wrapFetchForExtraCa, with different path heuristics (looksLikeFilePath vs any non-PEM value is a path). Please make resolveExtraCa call readPemValue (one error class, one reader) instead of keeping two readers for one variable.

const result = await generateImage(withRegistryHeaders(model, registry), request, {
apiKey: registry.resolver(carrier ?? model, sessionId),
fetch: ctx.fetch ?? fetch,
fetch: ctx.fetch,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scope question. This change, and the ?? wrapFetchForExtraCa(fetch) swaps in embeddings, transcription, judgment, compaction, both web searches and hosted images, add NODE_EXTRA_CA_CERTS trust to paths that are unrelated to the base-URL variables in the title. It looks right on its own, but it is a separate behavior change. Could it be split into its own PR (with its own changelog line) so the OPENAI_BASE_URL decision above does not block it?

@@ -0,0 +1,152 @@
/**

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix (convention). No CHANGELOG.md entry under ## [Unreleased] in any touched package (ai, catalog, coding-agent, agent, utils), and the PR checklist leaves that box unchecked. The OPENAI_BASE_URL meaning change in particular needs a user-facing line (### Changed, or ### Breaking Changes if kept), plus ### Fixed lines for ANTHROPIC_BASE_URL/Foundry discovery and web search, with the PR link and @sjawhar credit per AGENTS.md.

@legion-implementer
legion-implementer Bot force-pushed the upstream/fix-vendor-base-url-env branch from 2e347d6 to 8a734e1 Compare December 1, 2026 07:40
…es on every path

OPENAI_BASE_URL and ANTHROPIC_BASE_URL now replace the vendor address on
every request that sends the vendor key for a built-in model. Before this
change, ANTHROPIC_BASE_URL moved only Anthropic chat, and OPENAI_BASE_URL
moved no request of a built-in openai model. Responses, Chat Completions,
model discovery, web search, remote compaction, image generation,
embeddings, transcription and the Decisions judge sent the key to
api.openai.com. Anthropic model discovery and web search sent it to
api.anthropic.com. In Foundry mode, web search sent the key to
api.anthropic.com without the client certificate.

One resolver for each vendor, in packages/catalog/src/compat/vendor-base-url.ts,
reads the variables, and Foundry mode's FOUNDRY_BASE_URL with its client
certificate. A provider-file baseUrl other than the vendor's own address
wins, as with XAI_BASE_URL. A built-in openai model under the variable is
built again at that address, so its request is the request for a
provider-file baseUrl with that value: no stateful Responses chaining by
default, and no file upload. Discovered rows keep the built-in address,
so the model cache stays valid after the variable is unset.

Each of these paths now also trusts the CA in NODE_EXTRA_CA_CERTS, as
chat does, when its caller gives no fetch of its own: it falls back to
the shim of pi-utils, not to Bun's own fetch. The image tool no longer
passes Bun's fetch down, so each image client falls back as before and
hosted image generation takes the shim.

A provider-file baseUrl already moves each of these paths. The variables
did not, and no config makes web search, compaction, the judge, image
generation, embeddings or transcription carry Foundry's client
certificate or trust the NODE_EXTRA_CA_CERTS CA. For ANTHROPIC_BASE_URL
and Foundry mode this is a defect in the library's own routing: chat
follows them, and the other paths sent the key to api.anthropic.com. For
OPENAI_BASE_URL the change gives the variable the meaning XAI_BASE_URL
already has: it replaces the vendor address, where it was a fallback for
a model with no address. A user who exports OPENAI_BASE_URL for another
tool now also sends the requests of the built-in openai models there.

It implements no ruling. Red to green: each row of
vendor-base-url-paths.test.ts and openai-vendor-base-url-flags.test.ts
whose request the change moves fails at the parent commit, where the
request reaches the vendor host or sends without the CA, and passes here.
Tests that assert a vendor's own address clear the variables through the
test helpers, so they pass with the variables exported.

Omp-Session: 01a22d4b-90a5-7749-872a-63a6da9e619f
@legion-implementer
legion-implementer Bot force-pushed the upstream/fix-vendor-base-url-env branch from 8a734e1 to 3263b1f Compare December 1, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix provider:openai Provider-specific issues for openai providers LLM provider-specific issues review:p2 triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants