AI glossary · Agents and tools
What is function calling (tool use)?
Also called: tool use, tool calling, tool calls
Definition
Function calling, also called 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 it works
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
Why it matters
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
Common confusions
- Function calling vs MCP
- Function calling is how one model asks for one tool in one API. MCP is a protocol for an app to discover and run tools from external servers; the app still hands those tools to the model through function calling.
- 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.
Go deeper
Try it and read more
- Free toolAI Token CounterCount tokens for GPT, Claude, Gemini, DeepSeek, Qwen and more.
- Free toolJSON RepairFix broken JSON from LLM output.
- Guide · 13 min readOpenAI vs Anthropic vs Gemini API message formats comparedOpenAI, Anthropic and Gemini message formats side by side: system prompts, roles, images, tool calls, streaming, usage fields and a tested converter.
- Guide · 11 min readWhat is MCP (Model Context Protocol)? A plain-English guideWhat the Model Context Protocol is, how hosts, clients and servers talk, what tools, resources and prompts do, which apps support it and how to use it safely.
Related
Related terms
- AI agentAn AI agent is a program in which a language model works towards a goal by repeatedly choosing a tool to call, reading the result and deciding the next step, until the task is done or a stop condition is reached.
- Structured outputsStructured outputs is an LLM API feature that constrains the model’s reply to a JSON Schema you supply, so the response parses and has the fields and types you asked for, unlike JSON mode, which only promises valid JSON.
- MCPMCP stands for Model Context Protocol, an open standard that lets AI applications such as Claude Code, ChatGPT or VS Code connect to outside tools and data through one common interface.
- OpenAI-compatible APIAn OpenAI-compatible API is a model API that accepts OpenAI’s Chat Completions request format, so you can call it with the official OpenAI SDK by changing only the base URL, the API key and the model name.
- TokenA token in AI is the unit of text a language model reads and writes, usually a whole word, part of a word or a punctuation mark, which the model sees only as a number from its vocabulary.