Skip to content

Coding agents and tool-use loops

Most of an agent's bill is a prompt it already sent

An agent resends a fixed system prompt, a stable tool schema and a growing transcript on every single turn. That prefix is billed at the cached input rate rather than the standard one, which is why the discount on this workload is 65–68% rather than 36–42%.

Computed on 400M input tokens a month with a 60% repeated prefix, and 8M output — the workload is named so the figure can be checked rather than believed.

  • No platform fee
  • OpenAI SDK compatible
  • Pay as you go
  • 7 models callable today

Send me the agent-workload breakdown

The full arithmetic behind the figure: fresh input, cached prefix and output, per model, worked on the volume you tell us rather than the reference one.

One email, no sequence. Or skip the email and create an account for $5 in credit.

Why agent bills look nothing like chat bills

A chat request sends a short prompt and reads back a short answer. An agent turn sends the system prompt, the tool schema, the file contents it has already read, the transcript so far, and then reads back a few hundred tokens of decision. Then it does it again. By the tenth tool call the request body is enormous and almost entirely identical to the ninth.

That repetition is the defining economic property of the workload, and it cuts both ways. It is why an agent can burn through a budget faster than anyone estimates from watching it work — the visible output is tiny and the invisible input is not. It is also why an agent is the workload where prompt caching does the most good, because the repeated portion is billed at a fraction of the standard input rate.

The reference workload this page quotes is 400M input tokens a month with a 60% repeated prefix, and 8M output. That cached share is deliberately conservative: a real coding agent with a fixed system prompt and a stable tool schema repeats considerably more than that, and the calculator further down lets you push the assumption up and watch the figure move.

What an agent month is made of

Priced on GLM-5.2 at the reference volume, the bill comes to $190 — and the biggest slice of it is the prefix, not the output. The repeated portion is billed at $0.16/M instead of $0.82/M, which is the single largest lever available on this shape of work.

The practical consequence is that agent cost optimisation is mostly prompt-structure work. Keep the stable material at the front of the request — system prompt first, tool schema next, then retrieved context, then the turn-by-turn transcript — so that the longest possible prefix stays byte-identical between turns. A cache entry lives roughly five minutes after its last use, which a busy loop keeps warm without trying.

One agent month on GLM-5.2, by line
$190
One agent month on GLM-5.2, by lineThe part of the request nobody reads is the part that costs the most, which is why prompt structure is a cost decision and not only a quality one.
  • Fresh input$13169%
  • Repeated prefix, billed at the cached rate$38.4020%
  • Output$20.4011%
The part of the request nobody reads is the part that costs the most, which is why prompt structure is a cost decision and not only a quality one.Computed from this site's published rates on the reference agent workload.
ModelInputOutputCached inputPublisher’s rateBelow publisher
Kimi K2.6$0.55/M$2.30/M$0.11/M$0.95 / $4.00/M42%
Kimi K3$1.85/M$9.00/M$0.37/M$3.00 / $15.00/M40%
GLM-5.2$0.82/M$2.55/M$0.16/M$1.40 / $4.40/M42%
DeepSeek V4 Pro$0.28/M$0.55/M$0.055/M$0.43 / $0.87/M37%
DeepSeek V4 Flash$0.090/M$0.18/M$0.018/M$0.14 / $0.28/M36%
Text models callable today. The cached column is the one that decides an agent bill.

Cached input applies automatically when a prefix repeats. There is no header to set, no flag to pass and no plan to be on — the rate is published per model and billed as published.

Move the cache slider

This is the calculator to spend real time in, because agent workloads are the case where the default assumptions are most wrong. Enter your monthly input and output volume, then set the cache slider to the share of input that repeats between turns.

At a cache share of zero the discount is the rate-card figure, 36–42%. Push it toward what a real agent loop repeats and it climbs to 65–68% and beyond. Both ends of that range come from the same catalogue and the same arithmetic; only the shape of the workload changes.

M
M
0% of input cached

An agent or chat loop resends the same system prompt on every turn. That repeated prefix is billed at the cached rate, and on most models that is a fifth of the standard input rate. Set this to zero if every request you send is different.

Cheapest for this shape of work
$12.60/mo on DeepSeek V4 Flash
Against the official rate
$19.6036%

That is $7.00 a month, or $84.00 a year, on the same tokens through the same model.

An estimate, not a quote — but it is computed from the same rate table the API bills from, so the only assumptions in it are the ones you set above. Third-party figures are those providers’ own published rates; where a provider does not publish one, the cell is blank rather than guessed.

Pointing an agent at this endpoint

Agent frameworks are built on the OpenAI-compatible surface, so the loop itself does not change. Tool definitions, tool_choice and the assistant message carrying tool calls all have the shape your framework already emits.

  1. 1

    Swap the base URL in the agent's client

    One constructor argument. The loop keeps its retries, its tool registry and its transcript handling, because none of those touch the transport.

  2. 2

    Choose the model for the loop, not for the benchmark

    Kimi K3 holds reasoning together across long tool-use chains and carries the largest context window in the catalogue; DeepSeek V4 Flash is the one to reach for on the high-frequency, low-stakes steps. Mixing them across steps of the same loop is normal and is often the largest saving available after caching.

  3. 3

    Put the stable material first and leave it alone

    Order the request so the invariant prefix is byte-identical between turns: system prompt, tool schema, retrieved context, then the transcript. Anything that mutates near the front of the request — a timestamp, a shuffled tool list, a re-serialised schema — silently invalidates the cache for everything after it.

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://router.xark.io/api/v1"   # ← the only line that changes
)

response = client.chat.completions.create(
    model="moonshotai/kimi-k3",
    messages=[{"role": "user", "content": "Hello"}]
)
The agent loop is unchanged; only the client's base URL moves.

Your prepaid balance is a hard ceiling on every request, which is the property that matters most when the thing spending the money is a loop rather than a person. A runaway agent stops at what you have already paid.

Send me the agent-workload breakdown

The full arithmetic behind the figure: fresh input, cached prefix and output, per model, worked on the volume you tell us rather than the reference one.

One email, no sequence. Or skip the email and create an account for $5 in credit.

Per-model, on the rate card and on an agent loop

The two numbers below are the same catalogue measured against two different shapes of work. The first assumes every input token is billed fresh, which is true of a one-shot request. The second applies the reference agent workload, where most of the input is a prefix that has already been sent.

Kimi K2.6
42% below the publisher's rate on the rate card, 68% on the reference agent workload. Cached input is $0.11/M against a standard input rate of $0.55/M.
Kimi K3
40% below the publisher's rate on the rate card, 65% on the reference agent workload. Cached input is $0.37/M against a standard input rate of $1.85/M.
GLM-5.2
42% below the publisher's rate on the rate card, 68% on the reference agent workload. Cached input is $0.16/M against a standard input rate of $0.82/M.
DeepSeek V4 Pro
37% below the publisher's rate on the rate card, 66% on the reference agent workload. Cached input is $0.055/M against a standard input rate of $0.28/M.
DeepSeek V4 Flash
36% below the publisher's rate on the rate card, 65% on the reference agent workload. Cached input is $0.018/M against a standard input rate of $0.090/M.

The failure modes we will not paper over

Agent workloads fail in ways chat workloads do not, and the honest list is short enough to print.

No cross-model fallback
If an upstream fails, the request fails with its status and a machine-readable code. We do not retry against a different model, because in an agent loop a silently substituted model produces a plausible-looking trajectory that is wrong in a way the loop cannot detect.
Cache misses are silent by nature
A prefix that changes by one byte is a new prefix. If a bill comes in higher than the calculator predicted, the first thing to check is whether something near the front of the request is mutating between turns.
Availability is published, not assumed
7 of 24 catalogued models are callable today. Building a loop against a model marked unavailable produces an error at call time, so the marker is on every pricing row and every model page.
Per-key spending limits are not shipped
The account balance is the ceiling today, and it is a hard one. Per-key limits are on the roadmap; we would rather say so than let you design around a control that does not exist yet.

What agent teams say

Reserved for quotes from teams running production agent loops who have agreed to describe what happened to their bill.

No customer quote below has been approved for publication yet. Every card in this section is sample copy held in place until a real one replaces it, and none of it is offered as an endorsement.

  • Sample — pending customer approval

    Sample placeholder text, awaiting an approved customer quote about running a coding agent against a repeated system prompt.

    Founding engineer, developer tools company

  • Sample — pending customer approval

    Sample placeholder text, awaiting an approved customer quote about the cached-input line on the invoice.

    Platform engineer, e-commerce company

A loop, and its cost, side by side

A recording of an agent running a multi-step task with the per-request cost visible next to it, so the cached line can be watched rather than described.

Video not published yet

Agent loop with live cost accounting

Planned: an unedited run showing the cached-input line growing as the prefix repeats.

This space is reserved at its final size, so publishing the recording will not move anything below it.

Agent and caching questions

The mechanics, the limits, and the parts that are easy to get wrong in a loop that runs unattended.

How does prompt caching actually work here?

When you resend the same prefix — a system prompt, a fixed tool schema, a document you keep querying — it is served from the model's KV cache and billed at the cached-input rate, typically far below the standard input rate. It happens automatically, with no header to set, and a cache entry lives about five minutes after its last use. For agent loops it is usually the largest single line on the bill, which is why the cached rate has its own column on the pricing table rather than a footnote.

Do I have to enable caching or pass a flag?

No. There is nothing to switch on and no plan that gates it. If the prefix repeats, the repeated part bills at the cached rate. The only thing you control is whether your requests actually share a prefix, which is a matter of how you order the message array.

Where does the 65–68% figure come from?

From the same catalogue as every other number on this site, applied to a named workload: 400M input tokens a month with a 60% repeated prefix, and 8M output. The rate-card figure of 36–42% assumes every input token is billed fresh, which is true of a one-shot request and false of a loop. Both numbers are honest; they describe different shapes of work, and quoting either without naming the workload would not be.

Is a 60% cache share realistic for a coding agent?

It is conservative. A coding agent with a fixed system prompt, a stable tool schema and a file already in context repeats considerably more than that between turns. The figure was chosen low deliberately: quoting the conservative number and letting you find the larger one in the calculator is a stronger position than quoting the largest one and defending it.

What invalidates the cache?

Any change to the prefix, from the first differing byte onward. A timestamp injected into the system prompt, a tool list serialised in a different order, or a retrieved document reformatted between turns will all invalidate everything after the change. Keep the invariant material at the front and byte-identical.

Which model should an agent loop use?

Kimi K3 for the steps that need long-horizon reasoning across many tool calls — it carries the largest context window in the catalogue and holds together across long chains. DeepSeek V4 Flash for high-frequency, low-stakes steps. Using different models for different steps of one loop is normal and is usually the biggest saving available after caching.

Do tool calls and structured output work?

Yes. Tool definitions, tool_choice and the assistant message carrying tool calls all match the shape the OpenAI SDK expects, so an agent loop written against it runs unmodified. Frameworks built on that surface inherit the compatibility without knowing anything about us.

What stops a runaway agent from spending everything?

Your prepaid balance, enforced by the gateway on every request. It is a harder guarantee than a configurable cap because there is nothing to misconfigure — the loop stops at what you have already paid, not at an invoice. Automatic recharge is off by default; switched on, it is a fixed amount, capped at three recharges in any 24 hours, and disabled after three consecutive declines.

What happens when a model is rate-limited mid-loop?

The request returns 429 with rate_limit_exceeded and is not billed. That is deliberately a different code from the 429 with insufficient_credits you get on an empty balance, because the correct agent behaviour differs: back off in the first case, stop in the second.

Will you fall back to another model if one is unavailable?

No. Substituting a model changes the output, the price and the licence terms of what you receive, and inside an agent loop it produces a trajectory that looks plausible and is wrong. The request fails with the upstream status and a code your loop can branch on. Automatic cross-model fallback is not implemented and is not planned as a silent default.

Can I see cost per request?

Yes. The usage block comes back on the response in the same place the OpenAI SDK puts it, and per-request cost accounting is in the dashboard. For an agent this matters more than for chat, because the expensive requests are not the ones that produced interesting output.

How large a context window do I get?

Kimi K3 carries the largest in the catalogue, which is what makes whole-repository reasoning possible without a retrieval layer in front of it. Context sizes are published per model on the pricing table and on each model page rather than described in ranges.

Are the weights the same ones the publisher released?

Yes — same models, same ids, under their published open licences. What can differ between any two hosts of the same weights is quantisation, context handling and sampling defaults, so an evaluation set run against both paths is the right way to confirm behaviour rather than a claim from us.

Can I start without a card?

Yes. New accounts get $5 in credit with no card required, which is enough to run a loop end to end and read the cached-input line on your own traffic before deciding anything.

Run one loop and read the cached line

The argument on this page is arithmetic, and it is checkable on your own agent in an afternoon. The balance is a hard ceiling while you check it.

We guarantee at least 20% below the model publisher's own rate on every model we serve. The smallest discount in the catalogue today is 36%, so the guarantee has room in it by design.

Send me the agent-workload breakdown

The full arithmetic behind the figure: fresh input, cached prefix and output, per model, worked on the volume you tell us rather than the reference one.

One email, no sequence. Or skip the email and create an account for $5 in credit.

Related: Agent workload pricing · Full pricing table · Savings methodology