PRODUCTION SCENARIO
A client streams the Messages API. When Claude calls a tool, the deltas carry a delta.type of input_json_delta whose partial_json slices arrive as fragments: first
{"user_, then id": 4, then 2}.How should the client assemble the tool input before executing the call?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: Concatenate the slices per block index and parse at `content_block_stop`.
The slices are fragments of one serialized JSON string, so the client accumulates them per block index and parses the buffer once content_block_stop arrives for that block. Parsing a slice on its own throws immediately, since a fragment such as
id": 4 is not valid JSON. A partial-JSON parser is a supported way to read incremental values, but firing the tool on its first complete object runs with arguments the model has not finished sending. A delta is not a key-and-value unit: the model emits one key and value at a time, then chunks it across deltas.
Official Source: https://platform.claude.com/docs/en/build-with-claude/streaming ↗