Function calling is a way for an AI model to return a structured request that asks your program to run a specific piece of code, such as checking the weather or looking up a customer record, instead of only writing a text reply. In the basic setup, the model does not run the code itself: your application decides whether and how to run it, then hands the result back so the model can write a final answer. That loop is what turns a chatbot that only writes text into software that can look things up and take actions.
What is function calling, in plain English
OpenAI describes it this way: "Function calling (also known as tool calling) provides a powerful and flexible way for OpenAI models to interface with external systems and access data outside their training data" (OpenAI function calling guide). Anthropic uses a different label for the same idea: "Tool use (also called function calling) lets Claude call functions that you define or that Anthropic provides" (Anthropic tool use docs).
A few terms matter here, and vendors use them slightly differently.
- A tool is a piece of functionality that a developer tells the model it has access to. OpenAI's guide lists examples such as getting today's weather for a location, accessing account details for a given user ID, and issuing refunds for a lost order (OpenAI function calling guide).
- A tool call is a special kind of model response. The model decides it needs a tool and returns a request. For the prompt "what is the weather in Paris?", it could return a call to a get_weather tool with Paris as the location argument.
- The tool call output is what your code returns: structured JSON (a standard text format for data) or plain text. OpenAI's example output is
{"temperature": "25", "unit": "C"}, after which everything goes back to the model, which might reply "The weather in Paris today is 25C." - A function is a specific kind of tool, defined by a JSON schema, which is a machine-readable description of what data the tool accepts (OpenAI function calling guide).
The central point for non-developers: in the basic setup the model only writes the request. Your software runs the code and chooses what to send back.
Why AI models need tools
A plain language model predicts text from what it learned during training. That leaves gaps. The Toolformer paper from Meta AI Research (arXiv, February 2023) opens by noting that language models "struggle with basic functionality, such as arithmetic or factual lookup, where much simpler and smaller models excel" (Toolformer paper). Tools hand those jobs to software that is built for them, such as a calculator or a search engine.
Toolformer, a research model described in that paper, tested this idea. The paper calls it "a model trained to decide which APIs to call, when to call them, what arguments to pass, and how to best incorporate the results into future token prediction," using a calculator, a question-answering system, two different search engines, a translation system, and a calendar (Toolformer paper). The paper reported that Toolformer, based on the 6.7 billion parameter GPT-J model, outperformed the much larger GPT-3 (175 billion parameters) on several tasks, and that on math benchmarks it chose to call the calculator for 97.9 percent of examples.
Tools also give models access to information that did not exist when they were trained, and the ability to act: sending email, issuing refunds, writing to an app. Without a tool loop, a model can only produce text about those actions.
How function calling works, step by step
OpenAI's guide describes a five-step flow (OpenAI function calling guide):
- You make a request to the model, including the tools it could call.
- You receive a tool call from the model.
- You execute code on the application side, using the input from the tool call.
- You make a second request to the model, including the tool output.
- You receive a final response from the model, or more tool calls.
A few details inside that loop are worth knowing.
Model responses can include zero, one, or multiple tool calls, and OpenAI's best practice is to assume there may be several. The model may call multiple functions in one turn, known as parallel function calling, and developers can turn that off (OpenAI function calling guide).
You can also control how eager the model is to call tools with a setting called tool_choice. The options are auto (the default: call zero, one, or multiple functions), required (call one or more), forced (call exactly one specific function), and allowed tools (limit calls to a subset of the available tools). Setting it to none makes the model act as if no functions were passed (OpenAI function calling guide). Anthropic describes similar behavior: with the default tool choice of auto, Claude decides each turn whether to call a tool or respond directly, and it calls a tool when the request maps to the tool's described capability and the answer is not already in context (Anthropic tool use docs).
Who runs the code can vary. Anthropic distinguishes client tools, which your application runs, from server tools, which Anthropic runs on its infrastructure, such as web search, web fetch, code execution, and tool search (Anthropic tool use docs).

What a tool definition looks like
A function definition is a small block of JSON that tells the model what the tool is called, what it does, and what inputs it accepts. This example is the one in OpenAI's guide (OpenAI function calling guide):
{
"type": "function",
"name": "get_weather",
"description": "Retrieves current weather for the given location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and country e.g. Bogotá, Colombia"
},
"units": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Units the temperature will be returned in."
}
},
"required": ["location", "units"],
"additionalProperties": false
},
"strict": true
}Line by line, in plain words:
type: functionsays what kind of tool this is.nameis the identifier the model uses when it wants this tool, here get_weather.descriptiongives details on when and how to use the function. The model reads this text to decide whether the tool fits the request.parametersis a JSON schema for the inputs. Here it defines two: location, a string described as "City and country e.g. Bogotá, Colombia", and units, which must be either celsius or fahrenheit. Therequiredline says both inputs must be filled in, andadditionalProperties: falsesays no other inputs are allowed. OpenAI's strict mode needs both of those settings (OpenAI function calling guide).strictsays whether to enforce strict mode. Setting strict to true "will ensure function calls reliably adhere to the function schema, instead of being best effort," and OpenAI recommends always enabling it.
Functions are not the only tool type. OpenAI also offers custom tools with free-text inputs, and built-in tools that let the model search the web, run code, and access an MCP server (OpenAI function calling guide).
Function calling vs tool use vs MCP vs plugins
These terms overlap, which causes confusion.
- Function calling and tool calling are the same thing. OpenAI uses both names in one sentence: "Function calling (also known as tool calling)..." (OpenAI function calling guide).
- Tool use is Anthropic's name for the same mechanism: "Tool use (also called function calling)..." (Anthropic tool use docs).
- A function is narrower than a tool. In OpenAI's terms, a function is a specific kind of tool defined by a JSON schema, alongside custom tools and built-in tools (OpenAI function calling guide).
- MCP (Model Context Protocol) is an open standard for plugging outside tools and data into AI apps. Both vendors support it: OpenAI has a built-in tool that lets the model access an MCP server (OpenAI function calling guide), and Anthropic offers an MCP connector to connect to remote MCP servers (Anthropic tool use docs). See our plain-English guide to MCP for how the pieces fit together.
- Plugins is an older, product-level word. OpenAI's 2023 announcement named "ChatGPT Plugins" as an example of chatbots that answer questions by calling external tools (OpenAI announcement).
- Agents are programs that use tools repeatedly, in a loop, to reach a multi-step goal rather than answer one question. Function calling is the mechanism an agent runs on; see our explainer on what an AI agent is and how AI agents work.
Where you already see function calling
You do not need to be a developer to run into this. The examples in the vendor docs are everyday tasks: checking the weather, looking up an account, issuing a refund, searching the web, and running code (OpenAI function calling guide).
OpenAI introduced function calling in the Chat Completions API on June 13, 2023, for the gpt-4-0613 and gpt-3.5-turbo-0613 models. Developers describe functions, and the model can "intelligently choose to output a JSON object containing arguments to call those functions" (OpenAI announcement). The announcement gave concrete examples: "Email Anya to see if she wants to get coffee next Friday" becomes a call to send_email(to: string, body: string); "Who are my top ten customers this month?" becomes a call to an internal API; and the model can extract people data from a Wikipedia article into structured form.
The vendors also run some tools themselves. OpenAI's built-in tools let the model search the web, run code, and access an MCP server (OpenAI function calling guide). Anthropic's server tools, which run on its infrastructure, include web search, web fetch, code execution, and tool search (Anthropic tool use docs).
What can go wrong
Function calling adds moving parts, and each one can fail.
Wrong tool chosen. The model picks tools based on the user's request and the tool's description (Anthropic tool use docs). A vague description invites wrong choices, which is why OpenAI's best practices put so much weight on naming and describing tools clearly (OpenAI function calling guide).
Invented or missing arguments. If a prompt lacks a required parameter, Anthropic's docs say Claude Opus is much more likely to ask for it, while Claude Sonnet might ask but might also infer a reasonable value: asked "What's the weather?" with no location, Claude might guess "New York, NY." The docs add: "This behavior is not guaranteed" (Anthropic tool use docs). Strict mode exists to keep arguments inside the schema you defined (OpenAI function calling guide).
Cost in tokens. Tokens are the units models bill and measure context by. OpenAI states that functions are injected into the system message, so definitions count against the model's context limit and are billed as input tokens (OpenAI function calling guide). Anthropic bills tool use requests on input tokens (including the tools parameter) and output tokens, with extra usage-based charges for server tools such as web search per search, and notes that using tools adds a special system prompt with extra tokens (Anthropic tool use docs). So every tool you define adds input tokens to each request that includes it, whether or not the model calls it.
Untrusted tool output. OpenAI's 2023 announcement warned that "untrusted data from a tool's output can instruct the model to perform unintended actions," and advised developers to consume information only from trusted tools and to include user confirmation steps before actions with real-world impact, such as sending an email, posting online, or making a purchase (OpenAI announcement). In practice, text inside a tool result, such as a fetched web page, could try to steer what the model does next.
Actions with real-world impact. Because your code executes the calls, your code (and the humans overseeing it) own the consequences. The model writing "send this email" is not the same as the email being sent; the confirmation step in between is a design decision you make.

Tips if you are building with function calling
OpenAI's guide lists best practices worth copying (OpenAI function calling guide):
- Write clear, detailed names and descriptions for each function.
- Use the system prompt (the standing instructions sent with every request) to say when, and when not, to use each function.
- Apply the "intern test": could an intern use the function correctly given only what the model was given? If not, the description needs work.
- Do not make the model fill in arguments you already know.
- Keep the number of initially available functions small; OpenAI suggests aiming for fewer than 20 at the start of a turn, described as "just a soft suggestion."
- Use tool search to load rarely used tools only when they are needed (OpenAI says only gpt-5.4 and later models support it).
- Enable strict mode; OpenAI recommends always doing so.
- Assume a response may contain multiple tool calls, even if you expect one.
On the Anthropic side, remember that some server tools, such as web search and code execution, add usage-based charges on top of tokens, so factor those rates into your estimates (Anthropic tool use docs).
For engineering detail beyond this primer, our technical posts cover how teams test function calling with AST matching and sandboxed execution, and how JSON tool calling compares with agents that write executable code.
Finally, tool calls and their arguments arrive as structured data, usually JSON. If you are wrestling with getting reliable JSON out of a chatbot in general, our guide to JSON output in ChatGPT, Claude, and Gemini covers the related settings.
FAQ
Does the model run the function itself? In the basic setup, no. The model returns a request; your application executes the code and sends the output back (OpenAI function calling guide). The exception is server tools, which the provider runs on its own infrastructure (Anthropic tool use docs).
Is function calling the same as tool use? Effectively yes. OpenAI calls it function calling or tool calling; Anthropic calls it tool use and notes it is "also called function calling" (Anthropic tool use docs).
Does function calling cost extra? It costs tokens. Tool definitions are billed as input tokens and count against the context limit (OpenAI function calling guide), and Anthropic adds extra usage-based charges for server tools such as web search (Anthropic tool use docs).
What if the model does not have enough information to call a tool? It may ask you, or it may guess. Anthropic says Claude Opus is much more likely to ask for a missing required parameter, while Claude Sonnet might infer a value such as "New York, NY," and that this behavior is not guaranteed (Anthropic tool use docs).
Can function calling take actions that affect the real world? Yes, if your code performs them. OpenAI advises consuming information only from trusted tools and adding user confirmation steps before actions with real-world impact, such as sending an email, posting online, or making a purchase (OpenAI announcement).
Sources
- OpenAI, Function calling guide
- Anthropic, Tool use overview
- OpenAI, Function calling and other API updates (June 13, 2023)
- Toolformer: Language Models Can Teach Themselves to Use Tools (arXiv, February 2023)
- llms.blog, What is an AI agent? How AI agents work, explained simply
- llms.blog, What is the Model Context Protocol (MCP)? A plain-English guide
- llms.blog, Getting JSON output from ChatGPT, Claude, and Gemini
