Skip to content

Streaming: content_block_start reuses indices after web_search_tool_results #879

@mkdynamic

Description

@mkdynamic

This appears to be an API bug (not specific to the TS SDK).

Minimal reproduction case:

curl -X POST https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "anthropic-beta: web-search-2025-03-05" \
  -H "content-type: application/json" \
  -d '{"model":"claude-haiku-4-5","max_tokens":1024,"stream":true,"tools":[{"type":"web_search_20250305","name":"web_search"}],"messages":[{"role":"user","content":"Population of Spain?"}]}'

Observed:

content_block_start index=0 server_tool_use
content_block_start index=1 web_search_tool_result
content_block_start index=1 text  ← duplicate

Expected: Sequential unique indices (0, 1, 2, ...)

Per the docs:

Each content block will have an index that corresponds to its index in the final Message content array.

https://platform.claude.com/docs/en/api/messages-streaming

The streaming documentation shows web_search responses with sequential indices (0, 1, 2, 3...). The observed duplicate indices violate this contract.

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