Skip to content

Commit b885cd8

Browse files
committed
fix(providers): allow baseUrl override for anthropic
A pinned registry baseUrl silently discarded a user-configured endpoint, so local relays and enterprise gateways could not be used and misconfiguration only surfaced as a 401. Opt anthropic into allowBaseUrlOverride, repin the discarded-baseUrl warning fixture to google (still pinned), and add regression coverage for the override, the seeded-default path, and template rejection.
1 parent c4bf833 commit b885cd8

4 files changed

Lines changed: 91 additions & 13 deletions

File tree

‎src/providers/registry.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ export const PROVIDER_REGISTRY: readonly ProviderRegistryEntry[] = [
10771077
adapter: "anthropic",
10781078
baseUrl: "https://api.anthropic.com",
10791079
authKind: "oauth",
1080+
allowBaseUrlOverride: true,
10801081
featured: true,
10811082
oauthId: "anthropic",
10821083
jawcodeBundle: "anthropic",
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { expect, test } from "bun:test";
2+
import { routeModel } from "../src/router";
3+
import type { OcxConfig, OcxProviderConfig } from "../src/types";
4+
5+
/**
6+
* Regression coverage for the allowBaseUrlOverride opt-in on the anthropic
7+
* registry entry.
8+
*
9+
* Before the opt-in, the pinned registry endpoint silently outranked a saved
10+
* baseUrl and the router emitted the discarded-baseUrl diagnostic (see
11+
* tests/router-discarded-baseurl-warning.test.ts, which now pins google as
12+
* its fixture). Users routing Claude traffic through a local relay or an
13+
* enterprise gateway therefore could not redirect the provider at all. These
14+
* tests pin the new contract: a resolved user baseUrl wins, no warning fires,
15+
* and the registry endpoint remains the default seeded value.
16+
*/
17+
const PROVIDER = "anthropic";
18+
const REGISTRY_BASE_URL = "https://api.anthropic.com";
19+
const MODEL = PROVIDER + "/claude-sonnet-5";
20+
21+
function configFor(provider: OcxProviderConfig): OcxConfig {
22+
return {
23+
port: 10100,
24+
defaultProvider: PROVIDER,
25+
providers: { [PROVIDER]: provider },
26+
};
27+
}
28+
29+
function routeCapturingWarnings(config: OcxConfig): { baseUrl: string; warnings: string[] } {
30+
const warnings: string[] = [];
31+
const originalWarn = console.warn;
32+
console.warn = (...args: unknown[]) => { warnings.push(args.map(String).join(" ")); };
33+
try {
34+
const route = routeModel(config, MODEL);
35+
return { baseUrl: route.provider.baseUrl, warnings };
36+
} finally {
37+
console.warn = originalWarn;
38+
}
39+
}
40+
41+
test("anthropic honors a configured baseUrl override", () => {
42+
const { baseUrl, warnings } = routeCapturingWarnings(configFor({
43+
adapter: "anthropic",
44+
baseUrl: "https://claude-relay.example.test",
45+
} as OcxProviderConfig));
46+
47+
expect(baseUrl).toBe("https://claude-relay.example.test");
48+
// The override is applied, so the discarded-baseUrl diagnostic must not fire.
49+
expect(warnings).toHaveLength(0);
50+
});
51+
52+
test("anthropic keeps the registry endpoint when the seeded baseUrl is unchanged", () => {
53+
// providerConfigSeed copies the registry baseUrl into every saved config, so the
54+
// no-override case reaches the router as a config whose baseUrl equals the registry URL.
55+
const { baseUrl, warnings } = routeCapturingWarnings(configFor({
56+
adapter: "anthropic",
57+
baseUrl: REGISTRY_BASE_URL,
58+
} as OcxProviderConfig));
59+
60+
expect(baseUrl).toBe(REGISTRY_BASE_URL);
61+
expect(warnings).toHaveLength(0);
62+
});
63+
64+
test("anthropic requires a resolved baseUrl once override is enabled", () => {
65+
// allowBaseUrlOverride providers fail closed on a missing baseUrl instead of silently
66+
// re-pinning the registry endpoint; the seed guarantees real configs always carry one.
67+
expect(() => routeModel(configFor({
68+
adapter: "anthropic",
69+
} as OcxProviderConfig), MODEL)).toThrow(/Invalid baseUrl/);
70+
});
71+
72+
test("anthropic rejects an unresolved template baseUrl override", () => {
73+
expect(() => routeModel(configFor({
74+
adapter: "anthropic",
75+
baseUrl: "https://{region}.example.test",
76+
} as OcxProviderConfig), MODEL)).toThrow(/Invalid baseUrl/);
77+
});

‎tests/provider-registry-parity.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ describe("provider registry parity", () => {
561561
test("base URL override permission is registry-only and limited to opted-in providers", () => {
562562
const optedIn = PROVIDER_REGISTRY.filter(entry => entry.allowBaseUrlOverride);
563563

564-
expect(optedIn.map(entry => entry.id)).toEqual(["ollama", "vllm", "lm-studio", "moonshot", "qwen-cloud", "alibaba", "alibaba-token-plan-intl", "litellm"]);
564+
expect(optedIn.map(entry => entry.id)).toEqual(["anthropic", "ollama", "vllm", "lm-studio", "moonshot", "qwen-cloud", "alibaba", "alibaba-token-plan-intl", "litellm"]);
565565
for (const entry of optedIn) {
566566
expect(providerConfigSeed(entry)).not.toHaveProperty("allowBaseUrlOverride");
567567
}

‎tests/router-discarded-baseurl-warning.test.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import type { OcxConfig, OcxProviderConfig } from "../src/types";
77
* asserted in tests/router-template-baseurl.test.ts; these tests cover the diagnostic that
88
* tells the user it happened, so a wrong-region URL stops surfacing as a bare 401.
99
*
10-
* `anthropic` is the pinned fixture: a fixed remote registry endpoint, no `allowBaseUrlOverride`.
10+
* `google` is the pinned fixture: a fixed remote registry endpoint, no `allowBaseUrlOverride`.
1111
* Warnings dedupe per (provider, discarded URL, effective URL), so each test uses a distinct
1212
* discarded URL and the suite stays order-independent.
1313
*/
14-
const PINNED_PROVIDER = "anthropic";
15-
const PINNED_REGISTRY_BASE_URL = "https://api.anthropic.com";
14+
const PINNED_PROVIDER = "google";
15+
const PINNED_REGISTRY_BASE_URL = "https://generativelanguage.googleapis.com";
1616

1717
function configFor(providerName: string, provider: OcxProviderConfig): OcxConfig {
1818
return {
@@ -37,8 +37,8 @@ function routeCapturingWarnings(config: OcxConfig, model: string, times = 1): st
3737

3838
function routePinned(baseUrl: unknown, times = 1): string[] {
3939
return routeCapturingWarnings(
40-
configFor(PINNED_PROVIDER, { adapter: "anthropic", baseUrl } as OcxProviderConfig),
41-
`${PINNED_PROVIDER}/claude-sonnet-5`,
40+
configFor(PINNED_PROVIDER, { adapter: "google", baseUrl } as OcxProviderConfig),
41+
`${PINNED_PROVIDER}/gemini-3-pro`,
4242
times,
4343
);
4444
}
@@ -57,13 +57,13 @@ test("warns when a pinned provider discards a configured baseUrl", () => {
5757

5858
test("routing is unchanged by the warning", () => {
5959
const config = configFor(PINNED_PROVIDER, {
60-
adapter: "anthropic",
60+
adapter: "google",
6161
baseUrl: "https://routing-unchanged.example.test/v1",
6262
});
6363
const originalWarn = console.warn;
6464
console.warn = () => {};
6565
try {
66-
expect(routeModel(config, `${PINNED_PROVIDER}/claude-sonnet-5`).provider.baseUrl)
66+
expect(routeModel(config, `${PINNED_PROVIDER}/gemini-3-pro`).provider.baseUrl)
6767
.toBe(PINNED_REGISTRY_BASE_URL);
6868
} finally {
6969
console.warn = originalWarn;
@@ -155,7 +155,7 @@ const ALIBABA_INTL_BASE_URL = "https://token-plan.ap-southeast-1.maas.aliyuncs.c
155155

156156
test("alibaba-token-plan is pinned to Beijing and warns about a saved international URL", () => {
157157
const config = configFor("alibaba-token-plan", {
158-
adapter: "openai-chat",
158+
adapter: "google",
159159
baseUrl: ALIBABA_INTL_BASE_URL,
160160
});
161161
const warnings = routeCapturingWarnings(config, "alibaba-token-plan/qwen3.8-max");
@@ -176,7 +176,7 @@ test("alibaba-token-plan is pinned to Beijing and warns about a saved internatio
176176

177177
test("alibaba-token-plan-intl honors its configured international endpoint silently", () => {
178178
const config = configFor("alibaba-token-plan-intl", {
179-
adapter: "openai-chat",
179+
adapter: "google",
180180
baseUrl: ALIBABA_INTL_BASE_URL,
181181
});
182182

@@ -187,7 +187,7 @@ test("alibaba-token-plan-intl honors its configured international endpoint silen
187187

188188
test("alibaba-token-plan-intl honors its pay-as-you-go choice too", () => {
189189
const payg = "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
190-
const config = configFor("alibaba-token-plan-intl", { adapter: "openai-chat", baseUrl: payg });
190+
const config = configFor("alibaba-token-plan-intl", { adapter: "google", baseUrl: payg });
191191

192192
expect(routeCapturingWarnings(config, "alibaba-token-plan-intl/qwen3.7-max")).toEqual([]);
193193
expect(routeModel(config, "alibaba-token-plan-intl/qwen3.7-max").provider.baseUrl).toBe(payg);
@@ -197,7 +197,7 @@ for (const { label, id, adapter, baseUrl } of [
197197
{
198198
label: "a provider that opts into baseUrl override",
199199
id: "ollama",
200-
adapter: "openai-chat",
200+
adapter: "google",
201201
baseUrl: "http://ollama.lan:3210/v1",
202202
},
203203
{
@@ -209,7 +209,7 @@ for (const { label, id, adapter, baseUrl } of [
209209
{
210210
label: "a provider absent from the registry",
211211
id: "my-custom-provider",
212-
adapter: "openai-chat",
212+
adapter: "google",
213213
baseUrl: "https://custom.example.test/v1",
214214
},
215215
] as const) {

0 commit comments

Comments
 (0)