Function Calling
Function calling lets a model decide when to call tools that your application exposes. OpenModels supports the OpenAI-compatible tools format on models that support tool calling.
Not every model supports tools. Before using function calling in production, verify tool support for the selected model and provider route, because parameter support can vary by upstream provider.
The examples below use <tool-capable-model> as a placeholder. Replace it with a model and route that you have verified supports tool calling.
How it works
- Define one or more tools with JSON schemas.
- Send the user message and
toolstoPOST /chat/completions. - Check whether the assistant returned
tool_calls. - Execute the matching function in your application.
- Send the tool result back as a
role: "tool"message. - Ask the model to produce the final answer.
Request
If the model chooses a tool, the assistant message includes tool_calls:
Your application executes get_weather, then sends the result back:
Python
Node.js
Tool choice
Use tool_choice to control whether the model can call tools:
Production guidance
- Only execute tools that your application explicitly allowlists.
- Validate and parse
function.argumentsbefore calling any internal system. - Keep tool schemas small, typed, and specific.
- Treat tool output as untrusted input when sending it back to the model.
- If the model returns no
tool_calls, handle the assistant message as a normal text response. - Prefer non-streaming function calling first. Streaming tool calls require accumulating partial
delta.tool_callsarguments before execution.
Billing
Function calling uses the same credit-based billing as normal chat completions. Credits are consumed based on the input tokens, generated output tokens, tool call messages, and tool results included in the conversation.