Skip to content

webSearch_20250305 with streamText throws "BaseError: text part X not found" #880

@michaelfuest

Description

@michaelfuest

Description
When using Anthropic's webSearch_20250305 tool with streamText, the stream consistently fails with a "text part X not found" error after the web search returns results. The error occurs 100% of the time when streaming.

Environment
ai: ^5.0.65
@ai-sdk/anthropic: ^2.0.25
Node.js: v22.x
Model: claude-sonnet-4-5 (also tested with other Claude models)

Steps to Reproduce

import { anthropic } from "@ai-sdk/anthropic";
import { streamText } from "ai";

const result = streamText({  model: anthropic("claude-sonnet-4-5"),  prompt: "What's the weather in Munich today?",  tools: {    web_search: anthropic.tools.webSearch_20250305({ maxUses: 5 }),  },});

for await (const part of result.fullStream) {
  console.log(part);
}

Expected Behavior
Stream completes successfully with web search results incorporated into the response.

Actual Behavior
Stream fails with error:
BaseError: text part 2 not found

The web search tool executes successfully (returns encrypted results with URLs/titles), but the error occurs when Claude tries to cite/reference the results in its response.

Additional Context
The tool result contains encryptedContent fields - the error seems related to Claude's citation system referencing text parts that don't exist

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions