# KeyError: 'content' — streaming response chunk missing 'content' field in assistant message delta

- **ID:** `llm/streaming-assistant-content-empty`
- **Domain:** llm
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

When streaming responses that include tool calls, some chunks may contain only tool_calls without content; code that expects 'content' in every delta raises KeyError.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| openai>=1.0.0 | active | — | — |
| gpt-4-turbo-2024-04-09 | active | — | — |
| gpt-4o-2024-05-13 | active | — | — |

## Workarounds

1. **Check for both 'content' and 'tool_calls' in each delta: if 'tool_calls' is present, handle them separately; if 'content' is absent, initialize an empty string.** (95% success)
   ```
   Check for both 'content' and 'tool_calls' in each delta: if 'tool_calls' is present, handle them separately; if 'content' is absent, initialize an empty string.
   ```
2. **Use the OpenAI SDK's built-in streaming helper that automatically parses deltas into complete messages, such as client.beta.chat.completions.stream()** (90% success)
   ```
   Use the OpenAI SDK's built-in streaming helper that automatically parses deltas into complete messages, such as client.beta.chat.completions.stream()
   ```
3. **Implement a robust delta accumulator that tracks both content and tool_calls across chunks, assembling them into a complete message before processing.** (85% success)
   ```
   Implement a robust delta accumulator that tracks both content and tool_calls across chunks, assembling them into a complete message before processing.
   ```

## Dead Ends

- **** — This masks the error but does not handle tool_calls; the application may miss tool call data entirely (60% fail)
- **** — Skipping chunks may lose tool call data or other important deltas, corrupting the response (80% fail)
- **** — Disabling streaming eliminates the error but increases latency and defeats the purpose of streaming for user experience (40% fail)
