[PR #12634] fix: expand Anthropic detection and strip whitespace-only text blocks #14303

Open
opened 2026-02-16 18:19:06 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12634

State: open
Merged: No


What does this PR do?

When using Anthropic models through non-standard provider configurations (e.g.Github Copilot), the existing check model.api.npm === "@ai-sdk/anthropic" fails to detect them as Anthropic. This causes whitespace-only or empty text blocks to be sent to the API, which Anthropic rejects.

This PR:

  • Expand Anthropic provider detection in normalizeMessages to cover all Claude/Anthropic model variants (checking providerID, api.id, model.id, and api.npm), not just @ai-sdk/anthropic
  • Change empty content filtering from exact empty string (=== "") to whitespace-trimmed check (.trim() === ""), so whitespace-only text and reasoning blocks are also stripped

Should fix #2655

How did you verify your code works?

Manually test, verified I can continue with Claude model after a tool call cancel somehow insert an empty text block to request.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12634 **State:** open **Merged:** No --- ### What does this PR do? When using Anthropic models through non-standard provider configurations (e.g.Github Copilot), the existing check model.api.npm === "@ai-sdk/anthropic" fails to detect them as Anthropic. This causes whitespace-only or empty text blocks to be sent to the API, which Anthropic rejects. This PR: - Expand Anthropic provider detection in normalizeMessages to cover all Claude/Anthropic model variants (checking providerID, api.id, model.id, and api.npm), not just @ai-sdk/anthropic - Change empty content filtering from exact empty string (=== "") to whitespace-trimmed check (.trim() === ""), so whitespace-only text and reasoning blocks are also stripped Should fix #2655 ### How did you verify your code works? Manually test, verified I can continue with Claude model after a tool call cancel somehow insert an empty text block to request.
yindo added the pull-request label 2026-02-16 18:19:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14303