Skip to content

Conversation

@kiennq
Copy link

@kiennq kiennq commented Feb 7, 2026

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.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found two potentially related PRs that address similar issues with message normalization and content filtering:

  1. PR fix: strip incompatible thinking blocks when switching to Claude #8958 - "fix: strip incompatible thinking blocks when switching to Claude"

    • Related because it also deals with stripping content blocks (thinking blocks) when working with Claude/Anthropic models
  2. PR fix: strip reasoning parts when switching to non-interleaved models #11572 - "fix: strip reasoning parts when switching to non-interleaved models"

    • Related because it addresses stripping reasoning parts during model switching, which overlaps with the whitespace-only text block filtering in the current PR

These PRs appear to address related concerns around message content filtering and handling Claude/Anthropic model compatibility, though they may be focused on different specific scenarios (thinking/reasoning blocks vs. whitespace-only blocks).

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.

AI_APICallError: messages.157: all messages must have non-empty content except for the optional final assistant message

1 participant