Merge pull request #3000 from mpeter/fix/anthropic-small-model-base-url

fix(small-model): route anthropic provider through configured baseURL
This commit is contained in:
Bohdan Triapitsyn
2026-08-28 01:23:22 +03:00
committed by GitHub
4 changed files with 74 additions and 4 deletions
@@ -103,7 +103,10 @@ other runtime API.
`https://chatgpt.com/backend-api/codex/responses` with
`ChatGPT-Account-Id`; expired tokens are refreshed against
`auth.openai.com` (single-flight) and written back to `auth.json`.
- **Anthropic** (`type: api`): `/v1/messages` with `x-api-key`.
- **Anthropic** (`type: api`): `/messages` with `x-api-key`, against
`provider.anthropic.options.baseURL` when configured (used as-is, matching
`@ai-sdk/anthropic` — no `/v1` is inserted) or `https://api.anthropic.com/v1`
otherwise.
- **Google** (`type: api`): `generateContent` with `x-goog-api-key`; Gemini 3
uses `thinkingLevel`, Gemini 2.x uses `thinkingBudget: 0`, and all other
models omit `thinkingConfig` entirely.
+6 -3
View File
@@ -340,8 +340,11 @@ const callMessages = async ({ url, headers, modelID, prompt, system, maxOutputTo
return text;
};
const callAnthropic = async ({ apiKey, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => callMessages({
url: 'https://api.anthropic.com/v1/messages',
const callAnthropic = async ({ apiKey, baseURL, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => callMessages({
// Matches @ai-sdk/anthropic: baseURL is the full API prefix (commonly
// already ending in /v1), so it gets /messages appended as-is rather than
// having /v1/messages appended, which would double up a configured /v1.
url: `${(baseURL || 'https://api.anthropic.com/v1').replace(/\/+$/, '')}/messages`,
headers: {
'x-api-key': apiKey,
'anthropic-version': '2023-06-01',
@@ -705,7 +708,7 @@ export async function callSmallModel({ auth, catalog, workingDirectory, provider
}
if (providerID === 'anthropic') {
return callAnthropic({ apiKey, modelID, prompt, system, maxOutputTokens: tokens, responseSchema, timeoutMs, signal });
return callAnthropic({ apiKey, baseURL: providerConfig?.baseURL, modelID, prompt, system, maxOutputTokens: tokens, responseSchema, timeoutMs, signal });
}
if (providerID === 'google') {
return callGoogle({ apiKey, modelID, prompt, system, maxOutputTokens: tokens, responseSchema, timeoutMs, signal });
@@ -316,6 +316,69 @@ describe('callSmallModel — custom provider config', () => {
});
});
describe('anthropic provider custom baseURL override', () => {
const anthropicOk = (text) => ({
ok: true,
status: 200,
json: async () => ({ content: [{ type: 'text', text }] }),
});
it('respects provider.anthropic.options.baseURL over the hardcoded Anthropic endpoint', async () => {
readConfig.mockReturnValue({
provider: { anthropic: { options: { baseURL: 'http://127.0.0.1:3456/v1' } } },
});
fetchMock.mockResolvedValue(anthropicOk('ok'));
await callSmallModel({
auth: { anthropic: { type: 'api', key: 'dummy' } },
catalog: {},
workingDirectory: '/proj',
providerID: 'anthropic',
modelID: 'claude-haiku-4-5',
prompt: 'hi',
});
const { url, init } = lastCall(fetchMock);
expect(url).toBe('http://127.0.0.1:3456/v1/messages');
expect(url).not.toContain('api.anthropic.com');
expect(init.headers['x-api-key']).toBe('dummy');
});
it('uses a bare-host baseURL as-is without inserting /v1, matching @ai-sdk/anthropic', async () => {
readConfig.mockReturnValue({
provider: { anthropic: { options: { baseURL: 'http://127.0.0.1:3456' } } },
});
fetchMock.mockResolvedValue(anthropicOk('ok'));
await callSmallModel({
auth: { anthropic: { type: 'api', key: 'dummy' } },
catalog: {},
workingDirectory: '/proj',
providerID: 'anthropic',
modelID: 'claude-haiku-4-5',
prompt: 'hi',
});
expect(lastCall(fetchMock).url).toBe('http://127.0.0.1:3456/messages');
});
it('falls back to https://api.anthropic.com when no anthropic baseURL override is configured', async () => {
readConfig.mockReturnValue({});
fetchMock.mockResolvedValue(anthropicOk('ok'));
await callSmallModel({
auth: { anthropic: { type: 'api', key: 'sk-ant' } },
catalog: {},
workingDirectory: '/proj',
providerID: 'anthropic',
modelID: 'claude-haiku-4-5',
prompt: 'hi',
});
expect(lastCall(fetchMock).url).toBe('https://api.anthropic.com/v1/messages');
});
});
describe('catalog-based base URL (no config override)', () => {
it('uses the catalog api field when no config baseURL is set', async () => {
readConfig.mockReturnValue({});