From 51c636618a2f166b99f4b3397905dc3bc6a6d345 Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Wed, 10 Dec 2025 22:29:43 +0800 Subject: [PATCH] fix: parse error field in AssistantMessage to enable rate limit detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #401 The SDK defines AssistantMessage.error (including "rate_limit"), but the message parser was not extracting this field from the CLI response, making it impossible to detect rate limits or implement retry logic. Changes: - Added error field extraction in message_parser.py - AssistantMessage now properly includes the error field from the API - Applications can now detect rate_limit errors and implement retry logic Example usage: ```python async for message in client.receive_response(): if isinstance(message, AssistantMessage): if message.error == "rate_limit": # Implement retry logic await asyncio.sleep(60) ``` 🤖 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- src/claude_agent_sdk/_internal/message_parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/claude_agent_sdk/_internal/message_parser.py b/src/claude_agent_sdk/_internal/message_parser.py index 694c52c..312e4c0 100644 --- a/src/claude_agent_sdk/_internal/message_parser.py +++ b/src/claude_agent_sdk/_internal/message_parser.py @@ -120,6 +120,7 @@ def parse_message(data: dict[str, Any]) -> Message: content=content_blocks, model=data["message"]["model"], parent_tool_use_id=data.get("parent_tool_use_id"), + error=data["message"].get("error"), ) except KeyError as e: raise MessageParseError(