Skip to content

fix(anthropic): pass baseURL to client and handle thinking model responses#562

Open
ZITong926 wants to merge 1 commit into
di-sukharev:masterfrom
ZITong926:fix/anthropic-engine-baseurl-and-thinking-response
Open

fix(anthropic): pass baseURL to client and handle thinking model responses#562
ZITong926 wants to merge 1 commit into
di-sukharev:masterfrom
ZITong926:fix/anthropic-engine-baseurl-and-thinking-response

Conversation

@ZITong926

Copy link
Copy Markdown

Summary

  • Pass baseURL from config to the Anthropic SDK client. Without this, requests always go to 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).

  • Find the text content block instead of accessing content[0].text. Models with extended thinking (e.g. Claude with thinking enabled, or thinking-capable models behind proxies) return a thinking block at index 0 and the actual text at index 1. The old code gets undefined from content[0].text since the thinking block has no text property, producing empty commit messages.

Reproduction

  1. Set OCO_AI_PROVIDER=anthropic with a custom OCO_API_URL pointing to a proxy
  2. Run oco → gets 403 Forbidden (Bug 1)
  3. After manually fixing baseURL, run oco with 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

  • Verified with custom OCO_API_URL — no more 403
  • Verified with thinking model (GLM-5.1 via proxy) — commit message correctly extracted from text block
  • Non-thinking models still work (fallback: first text block is at index 0 as before)

🤖 Generated with Claude Code

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant