tool_calls object with the function name and arguments it wants to call. Your code executes the function, then submits the result back so the model can continue. This pattern is the foundation of most AI agents.
Check Model Support
Not every model supports tool calling. Before sendingtools in your request, check that the model’s supports_tools field is true in the GET /v1/models response. Sending tool definitions to a model that doesn’t support them returns a 400 error.
Define Tools
Pass atools array in your request body. Each entry has type: "function" and a function object with a name, description, and a JSON Schema parameters definition.
tool_choice to control whether and how the model uses tools:
Full Tool Calling Loop
A complete agent loop has four steps.Streaming Tool Calls
Whenstream: true is set, function.arguments arrives as a stream of string fragments across multiple chunks. Accumulate every fragment before calling json.loads — do not parse intermediate chunks.
max_tokens mid-call. You always receive complete, valid JSON — no custom repair logic needed on your side.
Parameters Reference
tool_choice values
finish_reason values related to tool calls
