Last verified

Agents & tools AI glossary

What is tool use in LLMs?

Tool use, also called function calling, is an LLM's ability to request that external code run — a search, a database query, a calculation — and to continue its answer using the result.

At a glance

  • How it works: You describe tools in the request; the model replies with a structured call; your code or the vendor runs it and sends the result back for the next step.
  • Why it matters: It is what turns a chatbot into an agent — and every tool definition, call and result is extra tokens on every turn.
  • What it costs: Tokens for definitions and results, a hidden tool-use system prompt, and per-call fees on some server tools — Anthropic's web search is billed per 1,000 searches.
  • Related to: MCP, AI agent, system prompt, context window.

How tool use works

A tool is a name, a description and a schema for its arguments, sent in the request's tools parameter. When the model decides a tool would help, it stops and returns a structured call — the tool's name and arguments — instead of a final answer. Your application runs the function and sends the result back in the next request; the model reads it and either answers or calls another tool. An agent is this loop run until the task is done.

Vendors also host tools themselves. Anthropic runs server-side tools such as web search, web fetch and code execution; xAI runs web search, X search, code execution and others. These run on the vendor's side and come back as results in the same response.

What tool use costs

Anthropic's pricing page lists where the tokens come from: the tools parameter with every tool's name, description and schema; the tool_use blocks the model writes; and the tool_result blocks you send back. On top of those, the API adds a tool-use system prompt whenever tools are present — 286 tokens on Claude Sonnet 5.5, 497 on Sonnet 4.6. Larger built-in toolsets carry more: declaring Anthropic's computer-use toolset adds about 4,500 input tokens to a request.

Server tools add usage fees. Anthropic charges for web search per 1,000 searches plus the tokens of the results, and says a failed search is not billed; web fetch has no fee beyond the tokens of the fetched content. xAI bills most of its server-side tools per 1,000 calls, with X search billed per item returned. And because tool results stay in the conversation, a large result — a web page, a file listing — is paid for again as input on every later turn.

Keeping tool use cheap

  • Define only the tools a task needs. Every definition is input on every call; dozens of rarely used tools are a standing tax. Anthropic's tool search tool defers definitions until the model asks for them.
  • Return small results. Trim a tool's output to what the model needs rather than dumping a whole document.
  • Clear stale results. Anthropic's context editing can clear old tool results from the history in long agent sessions.
  • Cache the stable part. Tool definitions come first in the prompt, so they cache well — as long as the list does not change between requests; Anthropic invalidates the whole cache when a tool definition changes.

Frequently asked.

Short answers to the questions that come up next.

Q · 01 Do tool definitions cost tokens? +
Yes, as input on every request that includes them — names, descriptions and schemas. Anthropic also adds a tool-use system prompt whenever any tool is present.
Q · 02 Is function calling the same as tool use? +
Yes. OpenAI popularised the term function calling; Anthropic and others say tool use. Both mean the model returns a structured call for your code, or the vendor, to execute.
Q · 03 How much does web search cost through an LLM API? +
It depends on the vendor: Anthropic charges per 1,000 searches plus the tokens of the results, and xAI charges per 1,000 web-search calls. See each vendor's pricing page for the current fee.
Q · 04 Why does my agent's input keep growing? +
Tool results are appended to the conversation and resent on every later turn. Trim results, clear stale ones, and cache the stable prefix.