Skip to content

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

Merged
di-sukharev merged 3 commits into
di-sukharev:masterfrom
ZITong926:fix/anthropic-engine-baseurl-and-thinking-response
Aug 22, 2026
Merged

fix(anthropic): pass baseURL to client and handle thinking model responses#562
di-sukharev merged 3 commits 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>

@di-sukharev di-sukharev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

zitong and others added 2 commits August 21, 2026 11:19
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>
@ZITong926
ZITong926 requested a review from di-sukharev August 21, 2026 03:36

@di-sukharev di-sukharev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@di-sukharev
di-sukharev merged commit a6649d2 into di-sukharev:master Aug 22, 2026
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.

2 participants