Book a free call

How Much Does Function Calling Cost to Run?

Function calling adds a model call plus the cost of every tool result it reads, so the bill grows with retries and long outputs. Here is how to count it.

Hertiv engineering teamReviewed by a senior engineer
6 min read
How Much Does Function Calling Cost to Run?
On this page

Short answer

Function calling costs what the model charges for the tokens it reads and writes, plus the cost of running the tools it calls. A single call is usually cheap, but retries, long tool outputs and multi-step agents multiply the bill. The total depends on your model, how many calls each task needs and how much data each tool returns.

What is function calling?

Function calling is a way for a language model to ask your software to run a function, such as looking up an order, checking a calendar or searching a database. The model does not run the code itself. It returns a structured request naming the function and its arguments, your code runs it, and the result goes back to the model.

Each round of this exchange is a model call. A simple task needs one call. A task that needs several tools, or one where the model retries after an error, needs several. The cost is therefore the cost of the model calls plus the cost of running the tools.

Function calling is the mechanism behind most AI agents: the agent plans, calls tools, reads results and calls again. If you are building an agent, its cost is largely the cost of its function calls. The basic idea is covered in the guide to what function calling is.

What makes up the cost of function calling?

The cost of function calling has four parts. The model charges dominate in most setups, but the tool and infrastructure parts grow as agents get more capable.

Cost part What you pay for What drives it
Input tokens Prompt, tools and prior results Tool descriptions, history length
Output tokens What the model writes Reasoning length, call count
Tool runs APIs, databases, compute Calls per task, data returned
Infrastructure Hosting, logs, monitoring Volume, retention, tracing

Input tokens are usually the largest line. Every call sends the tool descriptions again, plus the conversation history and the results of earlier calls. As a task runs longer, each new call carries more context, so later calls cost more than the first.

How do token prices work for tool calls?

Model providers charge per token, with separate rates for input and output tokens, and output tokens usually cost several times more than input tokens. Exact rates differ by model and change over time, so check the vendor's pricing page for the model you use and write "see vendor site" in any estimate you share.

For planning, teams often use round figures, such as a few dollars per million input tokens and a higher figure for output tokens, and treat them as planning rates rather than quotes. The point of the estimate is to compare designs, not to predict the invoice to the cent.

Two details matter. First, the tool descriptions count as input tokens on every call, so a long list of tools adds a fixed cost to each round. Second, tool results count as input tokens on the next call, so a tool that returns a large payload makes the following call more expensive. Keep both short.

What drives the bill up?

Five patterns drive function calling bills up, and all five are design choices rather than model prices.

  • Retries. A failed call is tried again, and each try costs tokens. A tool that fails often doubles or triples the cost of a task.
  • Long tool outputs. Returning a full record set when the model needs three fields wastes input tokens on every later call.
  • Too many tools. Every tool description is sent on every call. Twenty tools cost more per call than five, even if only one is used.
  • Long histories. Keeping the full conversation in context makes each call dearer. Summarise or trim history as tasks run on.
  • Loose loops. An agent that calls tools in a loop without a step limit can run for dozens of calls on one task.

The fix for most of these is the same: give the model only what it needs, cap the number of steps, and return small, filtered results from tools. The difference between agents and single calls is covered in ReAct agents versus function calling agents.

How to estimate your monthly cost

You estimate function calling cost by measuring one task, then multiplying by volume. Guessing from the price list alone misses the retries and the context growth that dominate real bills.

  1. Pick a typical task. Choose the task that will run most often, such as triaging a ticket or answering a product question.
  2. Log a sample. Run 50 to 100 real tasks and record the input and output tokens per call, the number of calls and the retries.
  3. Apply planning rates. Multiply the token totals by the vendor's rates for your model, or by planning rates if you are comparing models.
  4. Add tool costs. Include the API, database and compute cost of the tools themselves, which the model bill does not cover.
  5. Multiply by volume and add a margin. Scale the per-task cost to monthly volume, then add 10 to 20 percent for retries and edge cases.

Re-measure after any change to tools, prompts or models. A new tool description or a longer history window changes the per-task cost at once.

Example (hypothetical): a support triage agent

Example (hypothetical): a support team runs an agent that triages 500 tickets a day. Each ticket needs 2 function calls on average. Each call reads 1,500 input tokens and writes 300 output tokens.

Daily input tokens are 500 tickets x 2 calls x 1,500 tokens = 1,500,000 tokens. At a planning rate of $2.50 per million input tokens, that costs 1.5 x $2.50 = $3.75 per day. Daily output tokens are 500 x 2 x 300 = 300,000 tokens, which at a planning rate of $10 per million costs 0.3 x $10 = $3.00 per day.

The model cost is $3.75 + $3.00 = $6.75 per day, or $6.75 x 30 = $202.50 per month. With about 10% of tasks needing a retry, the bill rises to roughly $202.50 x 1.1 = $222.75 per month. The arithmetic shows the shape of the cost: input and output are close, and retries add a visible tenth.

What are the common mistakes?

The most common function calling cost mistakes are exposing too many tools, returning too much data, and running without a step limit.

  • Exposing every function. Registering the whole API as tools makes every call pay for descriptions the model never uses. Expose only what the task needs.
  • Returning full records. A search tool that returns 50 results when the model needs 3 wastes tokens on the next call. Filter and trim in the tool.
  • No step cap. An agent without a maximum step count can loop for a long time on a bad task. Cap steps and fail loudly.
  • No per-task logging. Without token logs per task, the bill is a mystery and the expensive tasks stay hidden.
  • Choosing the largest model by default. A smaller model often handles structured calls well. Test it before paying for the largest one.

Teams that want help designing the agent and its cost controls usually start with AI agent development, where tool design and guardrails are part of the build.

Key takeaways

  • Function calling costs input tokens, output tokens and tool runs, and later calls cost more because context grows
  • Tool descriptions and tool results both count as input tokens on every call
  • Retries, long outputs, too many tools and uncapped loops are what inflate the bill
  • Estimate from a measured sample of real tasks, not from the price list alone
  • Expose only the tools a task needs and trim what each tool returns

Frequently asked questions

Is function calling more expensive than plain chat?

Yes, usually. A plain chat call is one round of tokens, while function calling adds tool descriptions, extra rounds and tool results. The gap is small for a single call and large for a multi-step agent, which is why agents need a cost estimate before launch.

Does the model charge for tool results?

The model charges for tokens, not for tools. Tool results are charged as input tokens when they are sent back to the model, so a long result makes the next call more expensive. The tool itself may also cost money to run, which is a separate bill.

How can I cut function calling costs?

Expose fewer tools, return smaller results, trim conversation history, cap the number of steps, and test a smaller model for structured calls. Caching repeated tool results also helps when the same lookup runs many times a day.

Do failed function calls still cost money?

Yes. The tokens sent and received before the failure are already billed, and a retry bills again. This is why reliable tools matter: a tool that fails one time in ten adds roughly a tenth to the bill, plus the cost of the failed attempts themselves.

What is a reasonable cost per task?

It depends on the model and the task. Simple lookups with a small model can cost a fraction of a cent, while multi-step research with a large model can cost several cents. Measure your own tasks with a sample, and compare designs on that number rather than on a general benchmark.

Should I use the cheapest model for function calling?

Not always. Cheaper models can make more mistakes, which leads to retries and longer loops that erase the saving. Test two or three models on your own tasks and compare the total cost per completed task, including retries, before choosing.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: AI and agent systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Building an AI agent and want its tool costs under control? Talk to Hertiv.

A senior engineer replies within one business day. Or see our LLM Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call