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.