From d411985e3e2d0974766a2ff4b80b7be8ba971d80 Mon Sep 17 00:00:00 2001 From: zitong Date: Sat, 20 Jun 2026 14:33:47 +0800 Subject: [PATCH] fix(anthropic): pass baseURL to client and handle thinking model responses Two fixes for AnthropicEngine: 1. Pass `config.baseURL` to the Anthropic SDK client constructor. Without this, requests always go to the default `https://api.anthropic.com` even when `OCO_API_URL` is configured, resulting in 403 errors for users with custom API endpoints (e.g. corporate proxies). 2. Find the `text` content block instead of blindly accessing `content[0].text`. Models that return extended thinking (e.g. Claude with thinking enabled) put a `thinking` block at index 0 and the actual text at index 1. The old code would get `undefined` from `content[0].text` since the thinking block has no `text` property, producing empty commit messages. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/engine/anthropic.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/engine/anthropic.ts b/src/engine/anthropic.ts index 3716a24e..b980723c 100644 --- a/src/engine/anthropic.ts +++ b/src/engine/anthropic.ts @@ -21,6 +21,10 @@ export class AnthropicEngine implements AiEngine { this.config = config; const clientOptions: any = { apiKey: this.config.apiKey }; + if (this.config.baseURL) { + clientOptions.baseURL = this.config.baseURL; + } + const proxy = config.proxy; if (proxy) { clientOptions.httpAgent = new HttpsProxyAgent(proxy); @@ -65,7 +69,8 @@ export class AnthropicEngine implements AiEngine { const data = await this.client.messages.create(params); - const message = data?.content[0].text; + const textBlock = data?.content?.find((b) => b.type === 'text'); + const message = textBlock && 'text' in textBlock ? textBlock.text : undefined; let content = message; return removeContentTags(content, 'think'); } catch (error) {