EN

Language

Our editions

Written for each audience, not translated word for word.

Function calling: how a language model uses your tools

ExplainerBy Lucas Matías García TorresUpdated Data checked 5 min read

Reviewed by Lucas Matías García Torres on . How we work.

Leer en español

An industrial robotic arm placing small metal cubes connected by glowing orange cables

Short answer

Function calling (also called tool calling or tool use) on October 23, 2026: the model never runs your function. It returns the function name and arguments, your application runs it and sends the result back, and the loop repeats until the model answers. OpenAI, Anthropic and Google all offer an automatic mode, a mode that forces a tool call, a mode that forbids them and a strict schema option. Tool definitions are billed as input tokens on every request, and the vendors advise keeping roughly 10 to 20 tools active at a time.

Prices and limits change often: check the vendor's page before you pay. How we make money.

Function calling, also called tool calling or tool use, is how a language model gets things done outside its own text: it asks your program to run a function you described, with arguments it filled in, and then uses the result to answer. The short version on October 23, 2026: the model never runs anything itself. OpenAI's guide calls tool calling "a multi-step conversation between your application and a model", Google's documentation says "The model doesn't execute the function itself", and Anthropic says Claude returns "a structured call that your application runs". This guide explains the loop, the settings that control it, what it costs and the mistakes to avoid. It is based on the API documentation of OpenAI, Anthropic and Google, read on October 23, 2026; we have not benchmarked how accurately each model picks tools.

How function calling works, step by step

OpenAI's guide describes five steps, and the other two vendors follow the same pattern with different field names:

  1. Your application sends the request with tool definitions. Each tool has a name, a description and a JSON Schema for its parameters.
  2. The model replies with a tool call instead of text. It names the function and fills in the arguments. In Anthropic's API the response ends with stop_reason: "tool_use" and one or more tool_use blocks.
  3. Your code runs the function. It checks the arguments, calls your database or API and gets a result.
  4. You send the result back in a second request (Anthropic calls it a tool_result block).
  5. The model answers, or asks for more calls. OpenAI notes the flow can continue "for as many tool calls as the task requires".

Anthropic's own example makes it concrete. A get_weather tool takes a location. Asked about the weather in San Francisco, Claude replies with a call to get_weather and the argument {"location": "San Francisco, CA"}, the application looks up the weather, sends "15 degrees Celsius, partly cloudy" back, and Claude writes the final answer. That loop, repeated until a goal is reached, is what turns a chatbot into an agent.

Anthropic also distinguishes client tools, which run in your application, from server tools such as web search, web fetch and code execution, which run on Anthropic's infrastructure and return results in the same response.

The settings that control tool calls

Table: tool call settings in the three APIs (official documentation, checked October 23, 2026)

What you want OpenAI Anthropic Google (Gemini)
Let the model decide (default) tool_choice: "auto" tool_choice: {"type": "auto"} mode AUTO
Require at least one tool call "required" {"type": "any"} mode ANY
Require one specific tool name the function {"type": "tool", "name": ...} not covered in the page we read
Forbid tool calls "none" {"type": "none"} mode NONE
Arguments that always match the schema strict: true strict: true mode VALIDATED
At most one call per turn parallel_tool_calls: false disable_parallel_tool_use: true not covered in the page we read

Strict mode has rules. In OpenAI's API, "additionalProperties must be set to false for each object in the parameters" and "All fields in properties must be marked as required"; an optional field is written as a type that also allows null. Google describes VALIDATED simply as "Model ensures function schema adherence".

What tool calls cost

Tools are not free even when the function itself is. OpenAI states that "callable function definitions count against the model's context limit and are billed as input tokens". Anthropic bills the tools parameter, every tool_use block and every tool_result block as tokens, and adds a hidden system prompt that enables tool use: 286 tokens on Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 when tool_choice is auto or none, and 406 tokens on Haiku 5.5 when it is any or tool. Server tools such as web search add a charge per use.

The cost that surprises people is repetition. Every step of the loop is a new request that resends the conversation and the tool definitions. As an illustration, 15 tools described in about 150 tokens each add 2,250 tokens to every request; a task that takes six steps sends them six times, 13,500 input tokens before any real content. Our guide to what a token is explains how text turns into billable units, and prompt caching is the standard way to pay less for a long prefix that repeats.

How many tools, and how to describe them

The vendors agree that fewer, clearer tools work better:

  • OpenAI: "Aim for fewer than 20 functions available at the start of a turn", which it calls "just a soft suggestion", and "Keep the number of initially available functions small for higher accuracy".
  • Google: "Keep active set to 10-20 tools maximum", "Use specific types (integer, string, enum)" and "Validate function calls before executing".
  • Anthropic: when a required parameter is missing, Claude Opus "is much more likely to recognize that a parameter is missing and ask for it", while Claude Sonnet "might also infer a reasonable value". Its example shows a guessed "location": "New York, NY" for a question that never mentioned a city. For very large catalogs, Anthropic offers a tool search tool that loads tools on demand.

The practical rules follow: one job per tool, a description that says when to use it and when not to, enums instead of free text where you can, and validation in your code even with strict mode on, because a valid schema does not mean a correct value.

Function calling, MCP and agents

Function calling is the mechanism between your application and one model API. The Model Context Protocol works one level up: it standardizes how tool servers describe and expose their tools, so one server can be used by many applications. Our guide to what MCP is covers that layer, and Anthropic's API can connect to remote MCP servers directly. When you put function calls in a loop with a goal and a stopping rule, you have an agent; how to build an agent walks through a tested example with two tools, a step limit and human approval.

The model proposes, your code decides

Because your application runs every call, the safety controls live there, not in the model. Google's list ends with "Use appropriate authentication for external APIs", and the same logic applies everywhere: give each tool the narrowest permission it needs, check arguments against your own business rules, ask a person to approve anything irreversible or costly, and log every call. Treat what a tool returns, such as a web page or an email, as data rather than instructions, since it can contain text written to mislead the model. Our agents for business guide lists the risks to plan for before you connect a model to real systems.

What we checked

  • OpenAI: function calling is also known as tool calling; tool calling is a multi-step conversation between the application and the model in five steps; when the model calls a function you must execute it and return the result; tool_choice auto (default), required, a forced specific function or none; parallel_tool_calls false ensures zero or one tool is called; strict true requires additionalProperties false and all fields required, with null for optional fields; aim for fewer than 20 functions at the start of a turn (a soft suggestion); function definitions count against the context limit and are billed as input tokens. (OpenAI, )
  • Anthropic: tool use (also called function calling) returns a structured call that the application runs (client tools) or that Anthropic runs (server tools such as web_search, web_fetch, code_execution and tool_search); client tool calls end with stop_reason tool_use and are answered with tool_result blocks; disable_parallel_tool_use limits a turn to one call; strict true guarantees schema conformance; Claude Opus is more likely to ask for a missing required parameter while Claude Sonnet might infer one; pricing counts the tools parameter, tool_use and tool_result blocks, plus a tool-use system prompt of 286 tokens for Claude Opus 5.5, Sonnet 5.5 and Haiku 5.5 (auto or none) and 406 tokens for Haiku 5.5 (any or tool); server tools such as web search add usage-based charges. (Anthropic, )
  • Google Gemini: the model does not execute the function itself; modes AUTO (default), ANY, NONE and VALIDATED (model ensures function schema adherence); parallel calls for independent functions and compositional calls in sequence; best practices include keeping the active set to 10-20 tools maximum, using specific types, validating function calls before executing and using appropriate authentication for external APIs. (Google, )

What may change

  • Model names, tool-use system prompt token counts and default settings change with each model release. This page is reviewed quarterly.
  • We have not measured how accurately each model chooses tools; the advice on tool counts and descriptions is the vendors' own.

Frequently asked questions

Does the model run the function itself?

No. The model returns the name of the function and the arguments it chose, and your application runs the code and sends the result back. Google's documentation says it plainly: the model does not execute the function itself. Anthropic's server tools, such as web search, are the exception because Anthropic runs them for you.

Is function calling the same as tool use?

Yes. OpenAI writes function calling, also known as tool calling, and Anthropic writes tool use, also called function calling. The mechanism is the same: you describe tools with a name, a description and a JSON Schema, and the model decides when to call them.

How many functions can I give a model?

There is no single hard limit, but the vendors advise few. OpenAI suggests fewer than 20 functions available at the start of a turn and calls it a soft suggestion; Google recommends an active set of 10 to 20 tools at most. For large catalogs, load tools on demand.

Do tool definitions cost tokens?

Yes. OpenAI bills function definitions as input tokens and counts them against the context limit. Anthropic bills the tools parameter, tool calls and tool results, plus a tool-use system prompt of 286 tokens on its 5.5 models in auto mode. They are sent again on every step.

Can I force a model to call a tool?

Yes. Set tool_choice to required in OpenAI's API, to any in Anthropic's, or use mode ANY in Gemini. OpenAI and Anthropic also let you name one specific tool that must be called, which is useful when you only want structured output.

Sources

  1. Function calling (OpenAI API guide): five-step tool calling flow, tool_choice, parallel calls, strict mode and token usage, OpenAI. Accessed October 23, 2026.
  2. Tool use with Claude: client and server tools, tool_choice, strict tool use and tool use pricing, Anthropic. Accessed October 23, 2026.
  3. Function calling with the Gemini API: modes, parallel and compositional calls, best practices, Google. Accessed October 23, 2026.

Spotted an error or an outdated price? Tell us and we will fix it.

Change history

  • : First published. Checked against OpenAI's function calling guide, Anthropic's tool use overview and Google's Gemini function calling documentation on October 23, 2026.

Next review: .

Part of our Agents & Automation guide.

Other topics