AI glossary · Agents and tools
What is function calling (tool use) in LLMs?
Also called: tool use, tool calling, tool calls
Definition
Function calling, also called tool calling or tool use, is an LLM API feature in which the model replies with a structured request to run a function you described, with JSON arguments, which your code executes before sending the result back.
Explained
How does function calling work?
The model uses the result to continue, and it never executes anything itself. Function calling and tool calling are the same mechanism under two names: OpenAI uses both, and Anthropic calls it tool use. A model can also ask for several tool calls in one turn, which your code can run in parallel.
You send the model a list of tools, each with a name, a description and a JSON Schema for its arguments (parameters at OpenAI, input_schema at Anthropic). When a tool would help, the model returns a tool call instead of prose. OpenAI documents five steps: send a request with tools, receive a tool call, run the code, send the output back in a second request, and receive the final answer or more tool calls.
The model never executes anything. On Anthropic’s API the response has stop_reason: "tool_use" and a tool_use block; you run the function and reply with a tool_result block that quotes the call’s id. Arguments follow your schema on a best-effort basis unless you set strict: true on the tool. Repeating the round trip until the model stops asking is what makes an AI agent.
Example
One tool definition, and what it adds to every request
The definition below, serialised without spaces, is 68 tokens on o200k_base. OpenAI and Anthropic both bill tool definitions as input tokens, on every request that includes them, so an agent loop pays for them on every turn.
Anthropic also adds a tool-use system prompt whenever you pass tools: 286 tokens for Claude Sonnet 5.5 with tool_choice set to auto, from its pricing table. 20 tools of this size would come to about 1,646 tokens before the conversation starts. Claude’s tokenizer counts differently from o200k_base, so the definition’s share is an estimate.
| Part | Tokens | Source |
|---|---|---|
| This tool definition | 68 | Measured, o200k_base |
| Anthropic tool-use system prompt (Claude Sonnet 5.5, auto) | 286 | Anthropic docs |
| 20 definitions of this size plus that prompt | 1,646 | Computed |
{
"name": "get_order_status",
"description": "Look up the shipping status of one customer order by its ID. Use when the user asks where an order is.",
"input_schema": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "The order ID, for example ORD-10482"
}
},
"required": ["order_id"]
}
}Cost and quality
What do tool definitions cost?
Tool definitions are a fixed cost on every request, so a long list of rarely used tools costs money and leaves less room in the context window. Keep descriptions short but specific: the model picks a tool by its name and description.
Treat arguments as untrusted input. Validate them before running anything with side effects, and return errors as tool results so the model can correct itself.
Don’t mix up
Function calling vs tool calling vs MCP: what’s the difference?
- Function calling vs MCP
- MCP is a protocol for discovering tools on external servers; the app still hands them to the model through function calling, as our MCP guide explains.
- Function calling vs structured outputs
- OpenAI’s guidance: use function calling when the model should act through your tools, and structured outputs when you want the reply itself shaped to a schema.
FAQ
Questions people ask
What is the difference between function calling and tool calling?
There is none in practice: they are the same mechanism under different names. OpenAI’s docs say function calling is also known as tool calling; Anthropic calls it tool use. “Tools” is the broader word, because providers also offer built-in tools, such as web search or code execution, alongside the functions you define yourself.
Does the model run the function itself?
No. The model only returns the function name and JSON arguments. Your application checks them, runs the real code or API call, and sends the result back in the next request. That is why you should validate arguments before running anything with side effects, such as payments or deleting files, and repair malformed arguments with a tool like our JSON repair page.
How do tool calls differ between OpenAI and Anthropic?
The idea is identical, but the field names are not. OpenAI defines a tool’s arguments under parameters and returns tool_calls in Chat Completions; Anthropic uses input_schema, a tool_use block and a tool_result reply. Our message format guide shows them side by side, and the chat format converter translates between them.
Go deeper
Try it and read more
- Free toolChat Format ConverterConvert messages between OpenAI, Anthropic and Gemini.
- Free toolAI Token CounterCount tokens for GPT, Claude, Gemini, DeepSeek, Qwen and more.
- Free toolJSON RepairFix broken JSON from LLM output.
- Guide · 15 min readOpenAI vs Anthropic vs Gemini API message formats comparedOpenAI vs Anthropic message format, plus Gemini: system prompts, roles, images, tool calls, structured output, streaming and usage fields side by side.
- Guide · 13 min readWhat is MCP (Model Context Protocol)? A plain-English guideWhat is MCP? The Model Context Protocol in plain English: how hosts, clients and servers work, MCP vs APIs, which apps support it and how to use it safely.
Related