How do tool calls look in a stream?
In a stream, each tool call arrives in pieces under delta.tool_calls, keyed by index. The first piece has the id and function.name; later pieces add to function.arguments. When finish_reason is tool_calls, every call is complete.
calls = {}
for chunk in stream:
if not chunk.choices:
continue
d = chunk.choices[0].delta
for tc in d.tool_calls or []:
c = calls.setdefault(tc.index, {"id": None, "name": "", "args": ""})
if tc.id: c["id"] = tc.id
if tc.function and tc.function.name: c["name"] = tc.function.name
if tc.function and tc.function.arguments: c["args"] += tc.function.arguments
Parse args as JSON only after the stream finishes.
Good to know#
- Your key's account is responsible for your end users' text under the Abuse policy. What it means for apps
- New accounts get $5 of free credit; top up from $1 to $800 per purchase in Console › Billing › Credits. Billing
- Keep keys on your server, never in a browser or mobile app. Why
Still need help?#
- General support: support@clatterlabs.com or team@clatterlabs.xyz
- Infrastructure questions, or permanent deletion of your data (your whole account or one service): infrastructure@clatterlabs.xyz
We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Related articles
Still need help?
Tried the steps above and still stuck? Email us. We usually reply within the first hour, and always within 24 hours. A full support team is with you.
Infrastructure questions, or permanent deletion of your data
infrastructure@clatterlabs.xyzFor deleting your whole account or the data of one service.