Skip to main content
Tool calling lets you describe functions to the model and have it decide when and how to invoke them. Instead of generating free-form text, the model emits a structured 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 sending tools 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 a tools array in your request body. Each entry has type: "function" and a function object with a name, description, and a JSON Schema parameters definition.
Set 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

When stream: 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.
Piramyd’s automatic tool call integrity buffers argument deltas server-side, repairs any truncated JSON, and handles continuation if the model hits 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
Check supports_tools: true on a model before defining any tools, and always verify finish_reason before trying to parse tool_calls. For deeper context on how Piramyd handles large argument payloads during streaming, see the Tool Call Integrity concept page.