fix(anthropic): pass baseURL to client and handle thinking model responses#562
Open
ZITong926 wants to merge 1 commit into
Open
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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