An LLM tool call that your application runs has no price of its own at the model providers; it is paid in tokens: the tool definitions are billed as input on every request, the call the model writes as output, and the result as input to the next request. Only the providers' server-side tools, such as web search or code execution, add a fee per use. An AI agent repeats this round until its task is done, resending the system prompt, the tools and the growing history every time, so the cost of a task follows the number of steps it takes, not the price of one request.

How it works

The loop. For a tool the application runs itself, every call costs one more request: the model names the call in its response, the application runs it and delivers the result with the next request. At Anthropic this repeats for as long as a response ends with stop_reason: "tool_use", and the OpenAI Agents SDK runner works the same way. Since a model keeps nothing between requests, every round is a complete request carrying the whole context so far, as tokens, requests and context explains. Server-side tools loop at the provider instead: at Anthropic one request may cover several searches or code executions, and when it reaches the iteration cap the response ends with pause_turn, so continuing costs another request carrying the whole conversation.

What each round bills.

  • Definitions. The names, descriptions and schemas of every tool on offer are input tokens on every request; OpenAI places function definitions in the system message, where they take up context and are paid for like any other input. Anthropic adds a tool use system prompt of its own, sized per model and tool_choice on its pricing page.
  • Call. What the model writes as a call is output, and it stays in the history.
  • Result. It enters the next request as input and stays in the history, so every later round pays for it again.
  • Fees. Server-side tools charge per use as well, at the list prices in USD read on 2026-10-16 in the table. Anthropic's web fetch and Google's URL context cost only the tokens of the fetched content.
ToolOpenAIAnthropic (Claude API)Google (Gemini API)
Web searchUSD 10.00 per 1,000 calls, search content as tokens at model ratesUSD 10 per 1,000 searches, results as input tokens; a failed search is not billedGemini 3 and later: 5,000 search queries per month free, then USD 14 per 1,000; each query the model runs counts
Code executioncontainers per 20-minute session, USD 0.03 at 1 GB up to USD 1.92 at 64 GB, billed by the minute with a 5-minute minimum1,550 hours per organisation per month free, then USD 0.05 per hour per container, 5-minute minimum; free alongside current versions of web search or web fetchno fee; code and results billed as output and input tokens

Several agents. When an agent hands out work, requests multiply. In the Claude Agent SDK the model chooses when to hand off work and to how many subagents; each sends its own API requests and may delegate further, so requests branch out beneath a single prompt, which is why the SDK caps nesting depth, concurrent subagents and spend. A subagent starts with its own context and returns only its final message: that keeps the main agent's history short, but each subagent brings its own instructions and tools. Several calls in one round save rounds instead; OpenAI can switch them off with parallel_tool_calls, and Gemini supports parallel and chained function calls.

MCP servers. A Model Context Protocol server brings its whole tool list into the request. OpenAI first fetches the list, recommends keeping it in context and warns that a server with many tools leads to high cost and latency; allowed_tools imports only a subset. Anthropic's MCP connector switches individual tools on or off and can load them only when needed. How assistants reach cost data through MCP is covered in AI assistants and MCP.

Definitions on demand. OpenAI's tool search (gpt-5.4 and later) and Anthropic's tool search tool with defer_loading load a definition only when the model looks for that tool. OpenAI suggests fewer than 20 functions at the start of a turn, Google an active set of 10 to 20 tools at most.

What it means for your cost

Because every round resends the history, a task's input tokens grow faster than its steps. With B tokens of system prompt, definitions and task, and r tokens added by each round's call and result, round i carries B + (i − 1) × r input tokens, and a task of n rounds n × B + r × n × (n − 1) / 2. Twice the rounds cost more than twice the input, and large results drive the second term. The stable start of system prompt and definitions gets cheaper through LLM caching, batching and routing.

Cost per request therefore says little about an agent. Measure per completed task, as unit cost per request and outcome shows, and set limits per task, as budgets and stop rules for AI describes. A sequence for checking an agent:

  1. Steps per task, as a distribution, not an average.
  2. Definition tokens per request, measured with the provider's token counting.
  3. Result tokens per tool: which results are large and stay in the history.
  4. Fees per task: searches and container time.
  5. Repeated and failed rounds as a share of their own.
  6. Cached share of all input tokens.

Where it goes wrong

  • No step limit. A task that never converges keeps calling tools, and each round costs more than the last. The cause: no ceiling. The OpenAI Agents SDK stops after max_turns rounds, and the Claude Agent SDK caps depth, concurrency and spend.
  • Large results stay in context. A file or result list is paid for again in every later round. The cause: results are never trimmed. Anthropic's context editing clears old tool results past a threshold, but it invalidates the cached prefix and triggers new cache writes, so clear_at_least makes each clearing remove enough.
  • Every tool on every request. Definitions from several MCP servers ride along in each round while the task needs two tools. The cause: everything is loaded up front instead of filtered or loaded on demand.
  • Invalid calls are paid several times. A call with missing parameters costs several rounds. The cause: Anthropic documents that after an error result the model retries two or three times with corrections, each time with the whole context; strict tool schemas (strict: true) prevent such calls.
  • The SDK estimate is read as the bill. Reported cost differs from the invoice. The cause: the Claude Agent SDK computes total_cost_usd locally from prices it ships with, and Anthropic does not treat it as billing data; the AI provider usage exports are what counts.

Sources

Read on 2026-10-16. Anthropic pricing, how tool use works, handle tool calls, tool search tool, context editing, MCP connector, Agent SDK subagents and Agent SDK cost tracking; OpenAI pricing, function calling, MCP servers and Agents SDK: running agents; Google Gemini API pricing, function calling and grounding with Google Search.