fix(anthropic): pass baseURL to client and handle thinking model responses - #562
Conversation
…onses 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) <noreply@anthropic.com>
There was a problem hiding this comment.
Both fixes are correct in principle: the Anthropic client should receive baseURL, and the response should be searched for a text block. However, the resulting merge currently fails the required Prettier check. Please format it and add two regression cases to the existing anthropic.test: forwarding a custom baseURL, and a response containing a thinking block before the text block.
…e-baseurl-and-thinking-response
Add two regression cases to the existing anthropic.test covering the earlier fixes in d411985: - forwards a custom baseURL to the Anthropic client - extracts the text block when a thinking block precedes it Format src/engine/anthropic.ts with Prettier (the merged ternary on the text-block lookup exceeded the 80-col print width and failed the required format:check). Co-Authored-By: Claude <noreply@anthropic.com>
di-sukharev
left a comment
There was a problem hiding this comment.
The requested fixes are now complete. The custom base URL is forwarded to the Anthropic client, text extraction handles a leading thinking block, and both regressions are covered by focused tests. I also verified the combined merge with the other ready PRs: lint, typecheck, Prettier, build, 158 unit tests, and 34 end-to-end tests all pass. Approved.
Summary
Pass
baseURLfrom config to the Anthropic SDK client. Without this, requests always go tohttps://api.anthropic.comeven whenOCO_API_URLis configured, resulting in 403 errors for users with custom API endpoints (e.g. corporate proxies).Find the
textcontent block instead of accessingcontent[0].text. Models with extended thinking (e.g. Claude with thinking enabled, or thinking-capable models behind proxies) return athinkingblock at index 0 and the actual text at index 1. The old code getsundefinedfromcontent[0].textsince the thinking block has notextproperty, producing empty commit messages.Reproduction
OCO_AI_PROVIDER=anthropicwith a customOCO_API_URLpointing to a proxyoco→ gets 403 Forbidden (Bug 1)ocowith a thinking model → gets empty commit message (Bug 2)Fix
// Bug 1: pass baseURL const clientOptions: any = { apiKey: this.config.apiKey }; +if (this.config.baseURL) { + clientOptions.baseURL = this.config.baseURL; +} // Bug 2: find text block instead of content[0] -const message = data?.content[0].text; +const textBlock = data?.content?.find((b) => b.type === 'text'); +const message = textBlock && 'text' in textBlock ? textBlock.text : undefined;Test plan
OCO_API_URL— no more 403textblock🤖 Generated with Claude Code