Anthropic Python SDK streaming TypeError — Pydantic union discriminator returns raw dict instead of typed model
Fix Anthropic Python SDK streaming error TypeError unexpected event runtime type dict instead of typed model Includes evidence for Anthropic API troubleshooting demand.
Source-backedLast updated May 15, 20261 sourceNeeds local verification
Compare the failing environment with a known working setup, then change one configuration value at a time.
Updated
Verification status
Source-backed
Evidence
1 public source URL
Before you change production
This page includes public source URLs in the imported troubleshooting record. Compare those references with your version and environment before applying changes.
Reproduce the smallest failing action and save non-secret logs before changing configuration.
Check versions for Anthropic API, related SDKs, package managers, CI runners, and hosting providers.
Change one setting or dependency at a time, then rerun the same failing command or request.
Avoid destructive commands, credential rotation, billing changes, or security relaxations without a rollback plan.
What this error means
TypeError: Unexpected event runtime type, after deserialising twice — {'type': 'content_block_delta', 'index': 0, 'delta': {'type': 'text_delta', 'text': '...'}} — <class 'dict'> is a Anthropic API failure pattern reported for developers trying to fix anthropic python sdk streaming error typeerror unexpected event runtime type dict instead of typed model. Based on the imported evidence, treat this as a tool-specific troubleshooting page rather than a generic API error.
Why this happens
GitHub PR #1542 in anthropics/anthropic-sdk-python fixes streaming TypeError when Pydantic union discriminator returns raw dict. accumulate_event raises TypeError at isinstance check because event.delta is a dict instead of TextDelta. Multiple prior PRs (#1167, #1287, #1448, #1467) attempted partial fixes but left nested fields as raw dicts. Category mapped to Anthropic API — this is an SDK bug affecting streaming responses.
Common causes
GitHub PR #1542 in anthropics/anthropic-sdk-python fixes streaming TypeError when Pydantic union discriminator returns raw dict. accumulate_event raises TypeError at isinstance check because event.delta is a dict instead of TextDelta. Multiple prior PRs (#1167, #1287, #1448, #1467) attempted partial fixes but left nested fields as raw dicts. Category mapped to Anthropic API — this is an SDK bug affecting streaming responses.