[DOCS] Incomplete `Message` Union Type in Python SDK Reference
Documentation Type
Missing documentation (feature not documented)
Documentation Location
https://platform.claude.com/docs/en/agent-sdk/python
Section/Topic
The Message Types section, specifically the Message union type definition.
Current Documentation
###MessageUnion type of all possible messages. ``python Message = UserMessage | AssistantMessage | SystemMessage | ResultMessage``
What's Wrong or Missing?
The documentation for the Message union type is incomplete. It omits the StreamEvent type, which is a valid member of the union in the actual SDK implementation.
When a developer enables the include_partial_messages option in ClaudeAgentOptions, the iterator yields StreamEvent objects. Because this type is missing from the documented union, it causes type-checking failures (e.g., with MyPy) and leads to unhandled cases in code that uses isinstance checks or pattern matching to process the message stream.
Suggested Improvement
Update the Message union type definition to include StreamEvent:
Message
Union type of all possible messages.
Message = UserMessage | AssistantMessage | SystemMessage | ResultMessage | StreamEvent
Additionally, ensure the StreamEvent dataclass is listed under the Message Types section (it appears to be present in the types list but missing from this specific core union definition).
Impact
High - Prevents users from using a feature
Additional Context
- Source Code Verification: In the SDK source code (at
src/claude_agent_sdk/types.py), the type is explicitly defined as:
Message = UserMessage | AssistantMessage | SystemMessage | ResultMessage | StreamEvent
- Functional Impact: Developers relying on the documentation for type-safe message handling will miss
StreamEventlogic, which is critical when utilizing partial message streaming features. - Related Documentation: This discrepancy exists on the main Python SDK reference page at https://platform.claude.com/docs/en/agent-sdk/python.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗