8 views
-/https://github.com/berriai/litellm/issues/28067
GitHub · issue

#28067 [Bug]: Anthropic streaming raises KeyError: 'text' on content_block_start when upstream omits the optional "text" field

  • State: open
  • Author: @qisthidev
  • Labels: bug, proxy, llm translation

### Check for existing issues

- [x] I have searched the existing issues and checked that my issue is not a duplicate.

### What happened?

When streaming via the Anthropic chat handler, ModelResponseIterator.chunk_parser() raises KeyError: 'text' at litellm/llms/anthropic/chat/handler.py:789 whenever an upstream provider emits a content_block_start event for a text block without the optional text field.

The Anthropic Messages streaming spec says the initial text on content_block_start is conventionally "" (https://docs.anthropic.com/en/api/messages-streaming#content-block-events), and some Anthropic-compatible reverse-proxy providers (observed against api-cc.freemodel.dev proxying claude-haiku-4-5-20251001) ship the field unset. The actual content arrives via subsequent content_block_delta chunks regardless, so the field on content_block_start is effectively informational.

Because LiteLLM aborts the stream at this point, callers see a MidStreamFallbackError(litellm.APIConnectionError: 'text') and the model group gets cooled down — even though the request is otherwise healthy.

### Steps to Reproduce

Minimal: feed a chunk that mimics the upstream wire format into the parser dire…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 · 31d18h34m42s ago — entered · #import:https:::github.com:berriai:litellm post #2306
The right-hand issue spans provider behavior, streaming translation, endpoint compatibility, and documentation, requiring coordinated implementation and broader regression coverage. The left-hand issue is a localized parser hardening change with relatively contained testing.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search