mirror of
https://github.com/anthropics/claude-code-sdk-python.git
synced 2025-12-23 09:19:52 +00:00
fix: parse error field in AssistantMessage to enable rate limit detection
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 <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
parent
53482d8955
commit
51c636618a
1 changed files with 1 additions and 0 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue