Costs · November 5, 2026 · 7 min read

Hosted tool fees: what web search, fetch and code execution add to an agent run

Provider-hosted tools like web search, code execution and file search carry their own fees on top of tokens, and the tokens they pull into context often cost more than the fee. Here is how Anthropic, OpenAI and Google price them as of November 2026, with a worked example and the knobs that keep the bill sane.

Some links are affiliate links; we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases. Disclosure

Most cost math for agents stops at tokens: input price times input tokens, output price times output tokens, maybe a cache discount. That was close enough when every tool ran on your own servers. It stops being close once you turn on the tools the model provider runs for you, like web search, page fetching, a code sandbox or hosted file search. Those tools have their own line items, they are priced differently at each provider, and the per-call fee is often the smaller part of what they cost you.

This post walks through what the three big APIs charge for hosted tools right now, why the content those tools drag into the context window usually matters more than the sticker price, and the settings that let you cap both. All prices come from each provider's pricing page as fetched on November 5, 2026. They change, so check the linked pages before you budget off them.

The sticker prices, provider by provider

On the Claude API, Anthropic's pricing page lists web search at $10 per 1,000 searches, plus standard token costs for the search results. Each search counts as one use no matter how many results come back, and a search that errors isn't billed. Web fetch has no fee at all; you pay only for the fetched content as input tokens. Code execution is the interesting one. It is free when your request also includes the newer web search or web fetch tool versions (web_search_20260209 or web_fetch_20260209 and later). Used on its own, it is billed by container time with a five-minute minimum, 1,550 free hours per organization per month, and $0.05 per container-hour after that. The same page warns that if you attach files to a request, execution time is billed even when the tool is never called, because the files are preloaded into the container. If you run on Claude Managed Agents instead, session runtime of $0.08 per session-hour replaces the container-hour model, and it only accrues while a session is actually running, not while it sits idle waiting on you.

OpenAI's API pricing page lists web search at $10 per 1,000 calls for all current models, with search content tokens billed at the model's normal rates. The older web search preview for non-reasoning models costs $25 per 1,000 calls but makes the search content tokens free, and for gpt-4o-mini and gpt-4.1-mini on the non-preview tool, search content is billed as a fixed block of 8,000 input tokens per call. Hosted Shell and Code Interpreter run in containers priced by memory size: $0.03 for 1 GB, $0.12 for 4 GB, $0.48 for 16 GB and $1.92 for 64 GB per 20-minute session, with eligible sessions billed by the minute against a five-minute minimum. File search costs $2.50 per 1,000 tool calls in the Responses API, plus $0.10 per GB per day of vector storage after the first free gigabyte.

Google's Gemini API pricing takes a different shape. Grounding with Google Search on Gemini 3 and newer models includes 5,000 free search requests per month, shared across those models, then costs $14 per 1,000 requests, with a default cap of 1,500 requests per day per project. The Google Search grounding docs spell out the detail that catches people: you are billed for each search query the model decides to run, so a single prompt that triggers two searches counts as two billable uses. Older Gemini 2.5 models were billed per grounded prompt instead. Code execution, URL context and computer use on Gemini carry no separate fee. Generated code and execution results are billed as output tokens when created and as input tokens when the model reads them back.

The fee is rarely the expensive part

Every provider above says the same thing in slightly different words: the content a tool returns is billed as input tokens. Anthropic's page goes further and notes that web search results count as input tokens both during the turn they arrive and in every later turn of the conversation. That second part is where agent bills grow. An agent loop resends its history on each request, so a page of search results that lands on turn three gets paid for again on turns four through twelve unless it is cached or trimmed. We covered that history snowball in what tool calling really costs; hosted search is one of the fastest ways to feed it.

Here is a worked example using Claude Sonnet 5.5, which Anthropic lists at $2 per million input tokens, $10 per million output, $2.50 per million for five-minute cache writes and $0.10 per million for cache hits. The task shape is an assumption for illustration, not a measurement: a research agent runs twelve requests, makes eight web searches along the way, and each search adds about 6,000 tokens of results to the context.

The search fee is easy: eight searches at $10 per 1,000 is $0.08. The result tokens take more care. Eight searches at 6,000 tokens is 48,000 tokens, which costs about $0.10 the first time the model reads them. If those results arrive spread across the run, each batch gets reread on later requests. Suppose each one is reread six times on average. That is another 288,000 input tokens, or about $0.58 uncached. So the search-related cost of this one task is around $0.75, and the fee is barely a tenth of it. Scale to 1,000 tasks a day and you are looking at roughly $80 in search fees next to roughly $670 in result tokens.

Turn on prompt caching for the growing history and the picture flips. Writing those 48,000 tokens to a five-minute cache costs about $0.12, and the 288,000 tokens of rereads at the cache hit price come to under $0.03. The search-related cost drops to about $0.23 per task, and now the fee is a third of it. Our post on context compaction covers the tension here: trimming old tool results saves tokens but can break the cache prefix, so pick one strategy per stretch of the run instead of fighting yourself.

The same logic applies to fetch tools, which look free. A free fetch that returns a 40,000-token documentation page and then rides along for ten more turns is not free. It is just billed on a different line.

Definitions cost tokens before anything runs

Hosted tools also add fixed overhead to every request that declares them. Anthropic's pricing page lists the hidden tool-use system prompt that gets added whenever any tool is present; for Claude Sonnet 5.5 it's 286 tokens. The bigger toolsets are heavier. Declaring browser_toolset_20260801 with its default members adds about 6,600 input tokens per request, and computer_toolset_20260801 adds about 4,500. On a twenty-request run, a browser toolset you never used still cost you over 130,000 input tokens, minus whatever caching saves. Google's pricing page makes the same point for Gemini 4 Argon, noting that internal tool system instructions and function declarations are counted and billed when grounding is on.

The fix is boring and effective: only declare the tools a given step needs. If your planner step never browses, don't send it the browser toolset. If you use one agent configuration for everything, this is the first place to look when a bill comes in higher than your token math predicted.

Containers bill by the clock, not the call

Code sandboxes are priced by time, which behaves differently from per-call fees. A five-minute minimum means a run that executes one quick calculation pays for five minutes of container time. On OpenAI, a 64 GB container costs 64 times more per session than a 1 GB one, so leaving a large memory setting on for small jobs is pure waste. On Anthropic, the free monthly hours cover a lot of light use, but the preloaded-files rule means an agent that always attaches a spreadsheet just in case starts the meter on every request.

For agents that write code to sift search results, Anthropic's web search tool docs describe dynamic filtering in web_search_20260209 and later: Claude can run code that filters results before they reach the context window, keeping only relevant parts. Since code execution is free alongside those tool versions, this is one of the rare cases where turning on an extra tool can lower the bill, because fewer result tokens end up riding along in history.

The knobs worth setting

Start with hard caps on tool use per request. Anthropic's web search and web fetch tools both take a max_uses parameter, and the search docs recommend it as the hard constraint when steering through the prompt isn't enough. Web fetch also takes max_content_tokens, which the pricing page suggests as protection against accidentally pulling in a huge page. On Gemini, the 1,500 searches per day default cap is a rough backstop, but a per-request limit in your own loop is better, since one runaway task can eat a day's quota.

Next, read the usage fields instead of estimating. Anthropic returns server_tool_use.web_search_requests in each response's usage block, and code execution usage is reported there too. Log those next to token counts per task, and the question of whether search is earning its keep becomes a query instead of a guess. Our post on tracing agent runs with OpenTelemetry shows where to attach those numbers, and budget caps for agent runs covers turning them into limits that actually stop a run.

Finally, compare against running the tool yourself. A self-hosted fetch or a search API you already pay for can be cheaper at volume, but only if you also control how much of the result goes back into context. The provider's fee is a known number. The tokens are the part you design.

If you want a deeper grounding in the cost side of production LLM systems, AI Engineering by Chip Huyen covers inference optimization and serving trade-offs alongside the vendor docs.

Sources

Anthropic: Claude API pricing, Anthropic: Web search tool, Anthropic: Web fetch tool, OpenAI: API pricing, Google: Gemini Developer API pricing, Google: Grounding with Google Search.

Newsletter

The daily agent toolkit.

New tools, MCP servers and frameworks, in one short email every morning. Free, no spam. Sign up and get the free AI agent cost cheat sheet (PDF).