From 86d8a8f4c471605577716ab0f039c857e6261a0e Mon Sep 17 00:00:00 2001 From: h Date: Thu, 21 May 2026 13:00:40 +0200 Subject: [PATCH] fix: no null's in is_error --- src/claude_code_api/backend.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/claude_code_api/backend.py b/src/claude_code_api/backend.py index 16dee85..b29c25a 100644 --- a/src/claude_code_api/backend.py +++ b/src/claude_code_api/backend.py @@ -398,12 +398,17 @@ def _block_to_dict(block: ContentBlock) -> dict[str, Any]: "input": block.input, } if isinstance(block, ToolResultBlock): - return { + # ``is_error`` is optional on the wire; emitting ``null`` makes the + # Anthropic API reject the message with "Input should be a valid + # boolean". Omit it entirely when we don't have a value. + result: dict[str, Any] = { "type": "tool_result", "tool_use_id": block.tool_use_id, "content": block.content, - "is_error": block.is_error, } + if block.is_error is not None: + result["is_error"] = block.is_error + return result if isinstance(block, ThinkingBlock): return { "type": "thinking",