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",