Streaming tool calls: how Claude, OpenAI and Gemini send partial arguments, and how to put them back together
All three big APIs stream tool calls as fragments of JSON over server-sent events, but the event names, the indexes and the "it's done" signal differ. Here's what each one actually sends and how to assemble the pieces without running a tool on half an argument.
Some links are affiliate links; we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases. Disclosure
Turn on stream: true in an agent and the text part is easy. Deltas show up, you print them, the user sees words moving. Then the model decides to call a tool and the stream gets weird. You get a tool name early, then a pile of string fragments like {"loc, ation":"Par and is"}, and somewhere in there you have to decide when you're actually allowed to run the thing.
Every provider handles this a little differently. Claude, OpenAI's Responses API and Gemini's Interactions API all stream over server-sent events, all send tool arguments as partial JSON strings, and all expect you to glue those strings together yourself. Where they split is the event names, how they key parallel calls, and what counts as the "finished" signal. Get any of those wrong and you end up calling delete_file with a path that's only half written.
Why bother streaming tool calls at all
For a short call like get_weather, just wait for the whole response. Streaming earns its keep when a tool input is big, like a write_file call carrying 400 lines of code. Without it, the user stares at a spinner the whole time the model writes that argument. With it, you can show "Writing poem.txt..." the moment the tool name lands.
OpenAI's function calling guide pitches it the same way: streaming lets you show which function is being called as the model fills its arguments, and even display those arguments in real time. That's a UX win, not permission to act early.
Claude: content blocks with an index
Claude's streaming docs lay out a fixed flow. You get message_start, then a series of content blocks, each one opened with content_block_start, filled by any number of content_block_delta events, and closed with content_block_stop. After that come one or more message_delta events and a final message_stop. Each block carries an index that matches its spot in the final content array, so a text block might be index 0 and a tool_use block index 1.
The tool block starts with the name and id already set and an empty input: {}. The arguments then arrive as input_json_delta events with a partial_json string. In Anthropic's own example the fragments go {"location":, then "San, then Francisc, then o,, then CA"}. The docs say plainly that the deltas are partial JSON strings while the final tool_use.input is always an object, and that you should accumulate the strings and parse once you see content_block_stop for that index. The stop reason shows up later, in message_delta, as tool_use.
Two details trip people up. First, by default the API buffers each key and value until it's complete and only then streams it out in chunks, so you can see pauses while the model is generating a long value. Second, the stream can include ping events and even an error event mid-stream, like an overloaded_error that would have been an HTTP 529 without streaming. The docs also warn that new event types may be added and that your code should handle unknown types gracefully. Give your parser a default branch that skips what it doesn't recognize instead of throwing.
Fine-grained tool streaming
If buffering is too slow for you, Claude has fine-grained tool streaming. You set eager_input_streaming: true on each tool that needs it, and the API stops buffering and validating that tool's input before sending it. That cuts the wait for the first fragment of a large parameter, like a document or a code block.
The price is that you might get partial or invalid JSON. A response that ends on max_tokens can also chop a parameter off halfway. Anthropic's advice is to accumulate the fragments, guard the parse, and if the input won't parse, send it back to Claude instead of guessing. The pattern they document is a tool_result with is_error: true whose content is a JSON object like {"INVALID_JSON": "<the unparseable input you received>"}, built with a real JSON library so quotes get escaped properly. One more gotcha: the older fine-grained-tool-streaming-2025-05-14 beta header still turns this on for tools that leave the field unset, but the API rejects it alongside a computer use or browser use toolset entry. If you're still sending that header, move to the per-tool field.
OpenAI Responses: output items and argument deltas
The Responses API uses what OpenAI's streaming guide calls semantic events. Every event has a typed schema, and you listen for the ones you care about: response.created, response.output_text.delta, response.completed, error and so on.
For tool calls, the function calling guide describes three steps. A response.output_item.added event arrives for each function call, carrying an item with the name, an empty arguments string, the item id and the call_id. Then a run of response.function_call_arguments.delta events, each with an item_id, an output_index and a delta string. Then response.function_call_arguments.done with the full arguments string, followed by response.output_item.done with the finished item.
The key you join on is output_index, which the guide describes as the index of the output item in the response, one per function call. OpenAI's sample code keeps a map from output_index to the item from output_item.added and appends each delta's string to that item's arguments. Note the two different ids here. The fc_... item id is what deltas point at with item_id. The call_id is what you echo back in your function_call_output. Mixing them up is a classic way to get a "no matching tool call" error on the next turn.
Gemini Interactions: steps and partial arguments
Gemini's newer Interactions API follows the same shape with its own names. The function calling docs say that with streaming, function calls come through as a sequence of step.delta events, that arguments can stream as partial arguments, and that you must aggregate the deltas to rebuild the complete call before executing it. Over REST you hit the interactions endpoint with ?alt=sse.
The Python sample shows the bookkeeping. On step.start where event.step.type is function_call, it records the step id and name keyed by event.index. On step.delta with delta.type of arguments, it appends delta.partial_arguments to that entry. Text deltas come through the same event with delta.type of text. Only on interaction.completed does it run json.loads on each accumulated string. The sample also handles the case where step.start already carries arguments as a dict, so don't assume they always start empty.
One accumulator for all three
Once you line them up, the structure is the same everywhere. Something opens a call and gives you a name, an id and a slot number. Claude calls that slot index, OpenAI calls it output_index, Gemini calls it index on the step. Fragments arrive tagged with that slot. Something closes it. So the accumulator I'd write is boring on purpose: a map from slot to {id, name, buffer}, append on every argument delta, and parse only when you get that provider's close signal for the slot. That's content_block_stop on Claude, response.function_call_arguments.done on OpenAI, and interaction.completed in Google's sample.
Keying by slot matters most with parallel calls. Two tool calls can be in flight in the same turn, and if you append every fragment to "the current call," you'll weld two argument strings into one broken blob.
Treat the parse as a gate. If it fails, run nothing. Hand the error back to the model the way each provider expects (on Claude, the is_error wrapper above) and let it try again. If the turn ended on a token limit, assume the last argument got cut off, even if what you have happens to parse. And keep side effects behind the close signal. It's fine to show the user a growing preview of a file the model is writing. It's not fine to start writing that file to disk while the path itself is still streaming in.
Where the SDK helps
You don't always have to hand-roll this. Claude's docs note that the Python and TypeScript SDK helpers accumulate tool input for you and expose the parsed input as it streams. The SDKs can also stream internally and just hand you the final message, which matters for big max_tokens values where the SDK requires streaming to avoid HTTP timeouts. If all you want is reliability, take the final message. Raw events are only worth it when the user actually gains something from watching the arguments arrive.
If you're designing the bigger loop around all this, with retries, evals and how much UI to expose, AI Engineering by Chip Huyen covers that system-level side well. For the wire format itself, trust the provider docs linked above over any blog post, this one included. They change often, so re-read the event lists whenever you bump an SDK.