Menu

Streaming tool_calls on a non-OpenAI upstream
πŸ“°

Streaming tool_calls on a non-OpenAI upstream

DEV Community: apiΒ·pai zhangΒ·12 days ago
#DuUN36XI
#devtoapi#devto#dev#call#function
Long article (1601 words) β€” no AI summary yet.
Reading 0:00
15s threshold

Function calling is the part of the OpenAI contract most likely to break when the model behind the endpoint is not OpenAI's, and the breakage is rarely a clean error. Arguments arrive as fragments, content is null on the turn that emits a call, finish_reason becomes tool_calls instead of stop , and JSON Schema mode may not exist at all. This article walks a complete, runnable tool loop, then the streaming variant that accumulates fragments by index. It covers the three failures that account for nearly every broken integration, plus what changes when the endpoint in front of the model is a gateway that bills tool schemas as input tokens on every turn.

The shape of a tool turn

The model never runs your function. It returns a message whose content is null and whose tool_calls array holds one or more calls, each with an id and a JSON-encoded arguments string, and it sets finish_reason to tool_calls .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.