Use a current public model ID from Models or
GET /models. Example IDs and options must match the selected model’s advertised capabilities and limits.How it works
- You send
tools: a list of function definitions with JSON Schema parameters. - When the model wants a function, it responds with
tool_callsinstead of text, andfinish_reasonis"tool_calls". - You execute the function yourself, append the result as a
role: "tool"message, and call the API again. - The model answers using the result (or requests another call).
Defining tools
typemust be"function".name: 1-64 characters, letters, digits, underscores, dashes.descriptionis what the model reads to decide when to call it; write it well.parametersis a standard JSON Schema object. Up to 64 tools per request.
The tool call response
content is null on pure tool-call turns. arguments is a JSON string; parse it before use, and validate it since models can produce imperfect arguments. On reasoning models, reasoning_content may accompany the tool call.
Returning results
Append the assistant’s tool-call message and onerole: "tool" message per call, then request again:
tool_call_id must match the id from the assistant message. content is a string; JSON-encode structured results. The model then answers normally (finish_reason: "stop").
Streaming tool calls
With"stream": true, tool calls arrive as delta.tool_calls fragments in the standard OpenAI shape: the first fragment carries the id, type, and function name; subsequent fragments append to function.arguments. Accumulate by the fragment’s index until the final chunk reports finish_reason: "tool_calls". OpenAI SDK streaming helpers handle this assembly for you.
Controlling tool choice
parallel_tool_calls (boolean, default true) controls whether the model may request several tool calls in one turn.
Which models support it
Checkcapabilities.function_calling on GET /models, or the Function Calling tag on the models page. Sending tools to an unsupported model fails fast with 400 model_lacks_function_calling before anything is billed. Tool definitions and tool calls are ordinary tokens: definitions count as input, generated calls as output, at the model’s normal rates.