Skip to content

Blog

LLM Tool-Calling Costs: How We Cut an Assistant Session from 18 Calls to 9 or Fewer

How we measured Ciaren's Flow assistant per provider call, what our traces showed, the three changes in 0.4.1 and the limits of a one-provider benchmark.

About this post

Published
Reading time
8 min
Author
Ciaren team

Topics: flow-assistant, llm, engineering, performance

What does one turn of an AI assistant cost, and where does the waste hide? For Ciaren's Flow assistant, the unit that matters is the provider call, because every call in a tool loop resends the conversation so far. In Ciaren 0.4.1, a scripted session of three turns on DeepSeek went from 18 provider calls and about 121k input tokens to 7 to 9 calls and 41k to 55k input tokens, with about 90% of the input served from the provider's prompt cache. Three changes did it: validating an edit inside the same tool call, listing the usable columns when a column reference is wrong, and putting the node catalog first so prompt caches match across turns. Each reply now shows what it spent.

This post covers how we measured it, what the traces showed, and what the numbers do not prove.

Why calls, not tokens, are the unit

The assistant works as a tool loop. On each provider call the model gets the system prompt, the tool definitions and the transcript so far, and answers with tool calls: read a dataset schema, look up node settings, propose an edit, validate, finish. The server runs those tools against the installed node registry and appends the results, and the next call sends everything again plus the new results.

So a call late in a turn costs more than an early one, and a call that only recovers information the model should already have pays for the whole transcript again. Calls are also what Ciaren limits. One Build turn may make at most 14 provider calls, each request is capped at 48 KB, and by default each process allows 60 provider calls per rolling hour (CIAREN_ASSISTANT_TURNS_PER_HOUR). A turn that needs 14 calls uses almost a quarter of that hour.

How we measured

The benchmark is a script that drives the real application in process, through httpx.ASGITransport, with an isolated SQLite database and data directory. It talks to the real DeepSeek API with deepseek-flash and reasoning effort set to none. It uploads two synthetic CSVs (40 customers, 300 orders) and runs three turns with column names shared:

  1. Build: "Join orders and customers on customer_id. Keep completed orders from 2025. Sum revenue by region and order_month, add a bar chart of revenue by region, and write the result to a CSV."
  2. Change: "Add a Sort Rows step right before the File Output that sorts by revenue, highest first."
  3. Guides: "How do I run this flow automatically every Monday morning?"

The script wraps the function that makes one provider call and records, per call, the request size in bytes, input, cached, output and reasoning tokens, the names of the tools the model asked for, and the duration. Each proposal is applied before the next turn, as a user would.

What the traces showed

The change turn is the clearest example. Adding one Sort Rows node took six calls:

Six provider calls of one traced change turn. Call 3 looked up a column ref after a refusal that did not list columns, and call 5 was a separate validation. With the 0.4.1 tool results the same mistake would need four.

The model read the node schema and previewed the Group By output, which listed the columns by name, because names were shared in this session. It then wrote the sort with a column reference it had guessed, c2, instead of the name the preview had just shown. The edit was refused with "Use a column ref from the input schema." That message did not say which columns were valid, so the model spent a call on a profiled preview to find the right reference, retried the edit, called validate, and only then called finish. The request grew from 11.4 KB on the first call to 18.2 KB on the sixth.

Two of the six calls existed only because a tool result left something out. The build turn had the same two extra steps: a refused chart column and a separate validate call.

Three changes

Validate inside the edit. A successful propose_edit now runs the same checks as validate before it returns, and its result says validated: true, or lists the remaining issues. The finish rule changed with it: the model may finish when its last edit came back validated. That removes one full round trip from every turn that ends with a successful edit.

Moving checks into the edit had a side effect that an independent review of the change caught. If the checks ran past the 15-second tool limit, the whole edit came back as a refusal, and the model repeated operations the working graph already held. The checks now have their own deadline inside the tool limit, and running out of time returns the edit as applied but not validated.

Say which columns are valid. A refusal for a wrong column now lists the columns of that node's input, up to 24 and then a count of the rest. When names are not shared, the list holds references such as c0, so the refusal reveals nothing the model could not already see. A guessed name in an expression gets the same refusal whether or not that column exists, so the refusal cannot confirm a hidden name. The system prompt now also tells the model that, with names shared, the tools list columns by name and it should use them.

Put the stable part first. Prompt caches match on a prefix of the request. The first message of a turn used to start with the question and carry the node catalog further down, so a new question changed the prefix before the catalog. The catalog is the same on every turn, so it now leads the first message, and the next turn can reuse it from the cache. Anthropic tool turns also now request automatic prompt caching. One-shot calls, such as a guide answer, do not, because they have nothing to reuse and would pay the cache-write premium.

Results

Session (build, change, guides)Before 0.4.1After 0.4.1
Provider calls187 to 9
Input tokensabout 121k41k to 55k
Input served from cachenot recordedabout 90%

The range comes from repeated runs of the same script: the model does not take the same path every time. The first two changes drove the drop in calls. A run with only those two changes measured 7 to 8 calls and 41k to 50k input tokens. Reordering the catalog does not change the number of calls, and we have not measured its effect on cache hits separately.

A high cache share was not new. In the trace above, DeepSeek already served 94% of the change turn's input from its cache, because each call in a turn repeats the previous call's prefix. Cached input is usually billed at a lower rate, but it is still billed, and it still counts against the 48 KB request limit and the optional hourly token cap. Removing calls was the bigger lever.

What each reply shows

Every reply now ends with one line of usage, including replies that end without a change. For the traced change turn above, the line reads:

text
6 calls · 36,583 input tokens, 34,432 cached · 565 output tokens

Input tokens include the part read from the provider's cache, and output tokens include reasoning tokens, when the provider reports them. Providers report these under different fields: DeepSeek as prompt cache hits, OpenAI as cached tokens, Anthropic as separate uncached, cache-write and cache-read counts, which Ciaren adds so that "input tokens" means the same thing on every provider. Once a conversation has more than one reply, the panel also shows the conversation total.

There is no dollar figure. Rates differ by provider, model and account, and a number computed from a public price list would be wrong for many users. If you need a currency cap, set a spending limit in your provider's console. For a cap inside Ciaren, set CIAREN_ASSISTANT_TOKENS_PER_HOUR, which counts input and output tokens, cached input included. Since 0.4.1, guide answers, structural diagnoses and single-call plans report their usage and count toward that budget too.

What these numbers do not show

  • One provider, one model, one script. All numbers come from DeepSeek's deepseek-flash on three synthetic turns with column names shared. Other models take other paths through the tools, and other requests need more or fewer calls.
  • Anthropic caching is not verified live. The request now asks for automatic prompt caching on tool turns, and the adapter reads the cache counts from the response, but we have not yet confirmed the cache hits against the live Anthropic API.
  • Bedrock requests no caching. The Bedrock adapter reports cache counts if the service sends them, but it does not ask for caching.
  • No cost claim. We measured calls and tokens. What they cost depends on your provider's prices for cached and uncached input.

The per-request limits are in What the assistant can build, the hourly limits in Run the assistant on a server, and the prompt examples record how many calls each of 20 tested requests took. The assistant code is in backend/app/services/assistant_agent.py and assistant_provider.py in the Ciaren repository.

Keep reading