From f459206e4aeb21fa55857ee47d0431747209744c Mon Sep 17 00:00:00 2001 From: Matt Peter Date: Tue, 18 Aug 2026 23:44:09 -0400 Subject: [PATCH 1/2] fix(small-model): route anthropic provider through configured baseURL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Anthropic small-model dispatch (session-assist recap/suggestion, walkthrough, etc.) hardcoded https://api.anthropic.com/v1/messages, ignoring provider.anthropic.options.baseURL — the same override every other provider branch already respects. Any setup routing the anthropic provider through a local proxy (e.g. Meridian for Claude Max / Vertex) had the small-model call bypass the proxy and hit the real Anthropic API with whatever placeholder credential the proxy config uses, failing with 401 invalid x-api-key on every call. --- CHANGELOG.md | 1 + packages/web/server/lib/small-model/call.js | 6 +-- .../web/server/lib/small-model/call.test.js | 45 +++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30a8f4aa..76d45c88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ All notable changes to this project will be documented in this file. - Git: pull-request checks in Work status stay current as their status changes. - UI: the default dialog close button is easier to click or tap (thanks to @rockinrimmer). - Desktop/Windows: the close button now aligns correctly with the rest of the window chrome. +- Session assist: recaps and suggested follow-ups now work when the Anthropic provider is configured to use a custom endpoint; they previously failed every time instead of using that configured connection. ## [1.19.0] - 2026-08-19 diff --git a/packages/web/server/lib/small-model/call.js b/packages/web/server/lib/small-model/call.js index 27e183c8..86a447de 100644 --- a/packages/web/server/lib/small-model/call.js +++ b/packages/web/server/lib/small-model/call.js @@ -340,8 +340,8 @@ 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({ + url: `${(baseURL || 'https://api.anthropic.com').replace(/\/+$/, '')}/v1/messages`, headers: { 'x-api-key': apiKey, 'anthropic-version': '2023-06-01', @@ -706,7 +706,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 }); diff --git a/packages/web/server/lib/small-model/call.test.js b/packages/web/server/lib/small-model/call.test.js index 51097d80..7d6584bc 100644 --- a/packages/web/server/lib/small-model/call.test.js +++ b/packages/web/server/lib/small-model/call.test.js @@ -316,6 +316,51 @@ 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' } } }, + }); + 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('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({}); From 56b5e9971f2e56dce7ca687f14ecc88f0873c8cb Mon Sep 17 00:00:00 2001 From: Matt Peter Date: Wed, 19 Aug 2026 20:49:30 -0400 Subject: [PATCH 2/2] fix(small-model): don't double up /v1 in Anthropic baseURL override Match @ai-sdk/anthropic exactly: baseURL is the full API prefix, so /messages is appended as-is instead of unconditionally inserting /v1, which broke configs where the baseURL already ends in /v1 (the common form OpenCode itself passes to @ai-sdk/anthropic). Addresses review feedback from @btriapitsyn on PR #3000. --- .../server/lib/small-model/DOCUMENTATION.md | 5 ++++- packages/web/server/lib/small-model/call.js | 5 ++++- .../web/server/lib/small-model/call.test.js | 20 ++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/web/server/lib/small-model/DOCUMENTATION.md b/packages/web/server/lib/small-model/DOCUMENTATION.md index 1f6ee072..36a27532 100644 --- a/packages/web/server/lib/small-model/DOCUMENTATION.md +++ b/packages/web/server/lib/small-model/DOCUMENTATION.md @@ -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` while older Flash models use `thinkingBudget: 0`. - Everything else: OpenAI-compatible `/chat/completions` against the diff --git a/packages/web/server/lib/small-model/call.js b/packages/web/server/lib/small-model/call.js index 86a447de..9cefb6b5 100644 --- a/packages/web/server/lib/small-model/call.js +++ b/packages/web/server/lib/small-model/call.js @@ -341,7 +341,10 @@ const callMessages = async ({ url, headers, modelID, prompt, system, maxOutputTo }; const callAnthropic = async ({ apiKey, baseURL, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => callMessages({ - url: `${(baseURL || 'https://api.anthropic.com').replace(/\/+$/, '')}/v1/messages`, + // 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', diff --git a/packages/web/server/lib/small-model/call.test.js b/packages/web/server/lib/small-model/call.test.js index 7d6584bc..c787b23e 100644 --- a/packages/web/server/lib/small-model/call.test.js +++ b/packages/web/server/lib/small-model/call.test.js @@ -325,7 +325,7 @@ describe('callSmallModel — custom provider config', () => { it('respects provider.anthropic.options.baseURL over the hardcoded Anthropic endpoint', async () => { readConfig.mockReturnValue({ - provider: { anthropic: { options: { baseURL: 'http://127.0.0.1:3456' } } }, + provider: { anthropic: { options: { baseURL: 'http://127.0.0.1:3456/v1' } } }, }); fetchMock.mockResolvedValue(anthropicOk('ok')); @@ -344,6 +344,24 @@ describe('callSmallModel — custom provider config', () => { 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'));