Skip to content

Conversation

@pandemicsyn
Copy link
Contributor

Context

Occasionally when using the anthropic provider, users report running into the error:

"When thinking is disabled, an 'assistant' message in the final position cannot contain 'thinking'. To use thinking blocks, enable 'thinking' in your request."
... repeats...

Implementation

  • Updated filterNonAnthropicBlocks to conditionally strip thinking and redacted_thinking blocks based on the thinking parameter.
  • Added tests to verify behavior when thinking is enabled and disabled.

Screenshots

before after

How to Test

Get in Touch

- Updated filterNonAnthropicBlocks to conditionally strip thinking and redacted_thinking blocks based on the thinking parameter.
- Added tests to verify behavior when thinking is enabled and disabled.
@changeset-bot
Copy link

changeset-bot bot commented Dec 22, 2025

⚠️ No Changeset found

Latest commit: 12b56e8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pandemicsyn pandemicsyn marked this pull request as ready for review December 23, 2025 16:22
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Dec 23, 2025

✅ No Issues Found

4 files reviewed | Confidence: 95% | Recommendation: Merge

Review Details

Files:

  • src/api/transform/anthropic-filter.ts - Core filter function updated
  • src/api/providers/anthropic.ts - Caller updated
  • src/api/providers/anthropic-vertex.ts - Caller updated
  • src/api/transform/__tests__/anthropic-filter.spec.ts - Tests added

What was checked:

  • ✅ Security: No vulnerabilities introduced
  • ✅ Logic: Correct handling of thinking parameter
  • ✅ Backward compatibility: Optional parameter preserves existing behavior
  • ✅ All callers updated: Both Anthropic providers pass thinking param
  • ✅ Tests: Comprehensive coverage for enabled/disabled thinking scenarios
  • ✅ Edge cases: Empty messages after filtering are properly removed

Summary:
This PR correctly fixes the Anthropic API error "When thinking is disabled, an 'assistant' message cannot contain 'thinking'" by conditionally stripping thinking and redacted_thinking blocks from message history when the thinking feature is disabled (undefined). The implementation is clean, well-documented, and properly tested.

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