Skip to content
Cost Engineering8 min read·

An AI agent on your website: what it costs per conversation, and how to cap it

Vendor pages quote a monthly plan. This is the arithmetic underneath it: one eight-turn website conversation priced request by request on November 2026 model prices, with retrieval, tool calls, a retry and prompt caching included, followed by the six caps that stop an anonymous visitor turning it into an open-ended bill.

AI AgentsAgent IntegrationCost EngineeringPrompt CachingRate LimitingModel Routing

Search for how to integrate an AI agent into a website and the cost answers you find are plan pages: a chatbot vendor's monthly tiers, a message allowance, a price per seat. They tell you what the vendor charges. None of them shows what a single conversation costs underneath, which is the number you need the moment you build your own, and the one that decides whether a flat plan is a good deal or a bad one.

So this post is the arithmetic. One realistic website conversation, priced request by request on published model prices, with the parts that usually get left out of back-of-envelope estimates: retrieved context, tool calls, a retry and caching. Then the caps that keep the number bounded when the visitor is anonymous and nobody is watching. If you want the build itself (the server route, streaming, identity and prompt injection), that is in how to add an AI agent to your website without renting a widget. This one stays on the money.

What one turn actually sends

A visitor sees a question and an answer. The API sees a much larger request, because it is stateless: every turn resends everything the model needs to know, from the top. Here is the shape I used, which is close to a typical support or pre-sales agent on a business site.

Part of the requestTokensSent when
System prompt and tool definitions3,000Every request, identical each time
Retrieved context (three or four chunks from your docs)1,500Every turn, and it stays in the history afterwards
Visitor's message60Every turn
Agent's answer300 outEvery turn, then resent as history
Tool call (for example, checking an order or a booking slot)80 out, then 400 of results inTwo of the eight turns, as a second request
Retry (a regenerate click or a client resend)the last request again, 150 outOnce per conversation

Turn one sends 4,560 tokens. Turn eight sends 18,540, because by then it carries seven turns of history, each with its own retrieved chunks. The two tool turns each make two requests, so eight turns become ten requests, plus the retry: eleven requests, 134,040 input tokens and 2,710 output tokens. The visitor read about 2,400 tokens of answers. You paid to send fifty times that.

The worked example, priced

Prices are Anthropic's published API rates per million tokens, checked on 23 November 2026. I picked three tiers from one vendor so caching works the same way across them: Claude Opus 5.5 as the frontier model, Sonnet 5.5 in the middle, and Haiku 5.5 as the cheap one. Prices change, so check the current page before you reuse the numbers.

Per million tokensOpus 5.5Sonnet 5.5Haiku 5.5
Input$4.00$2.00$0.10
Cache write (5 minute)$5.00$2.50$0.125
Cache read$0.20$0.10$0.01
Output$20.00$10.00$0.50

Haiku 5.5's prices apply to prompts up to 100,000 tokens; above that it is billed at five times the rate. That threshold comes back when we get to session caps.

Without caching the arithmetic is two multiplications. With caching, each request reads whatever the previous request already sent at the cache-read price and writes only the new part. Across the eleven requests that is 117,760 tokens read from cache and 16,280 written to it.

One 8-turn conversationOpus 5.5Sonnet 5.5Haiku 5.5
Uncached: 134,040 input × input price$0.536$0.268$0.0134
2,710 output × output price$0.054$0.027$0.0014
Total, no caching$0.590$0.295$0.0148
Cached: 117,760 cache reads$0.024$0.012$0.0012
16,280 cache writes$0.081$0.041$0.0020
2,710 output$0.054$0.027$0.0014
Total, with caching$0.159$0.080$0.0046
Chart 1: one eight-turn website conversation, in cents
  • No caching
  • With caching

Claude Opus 5.5

No caching59.0¢
With caching15.9¢

Claude Sonnet 5.5

No caching29.5¢
With caching8.0¢

Claude Haiku 5.5

under 100K tokens per prompt

No caching1.5¢
With caching0.5¢

Anthropic API list prices as of 23 November 2026. Same conversation in every bar: 3,000-token prefix, 1,500 tokens of retrieval per turn, two tool calls and one retry. Caching cuts Opus and Sonnet by about 73% and Haiku by about 69%.

Scale that to a month. A thousand conversations is $590 on uncached Opus 5.5 and $80 on cached Sonnet 5.5. Twenty thousand is $11,800 against $1,600. The model matters, but caching alone moved Opus from 59 cents to 16, which is a bigger saving than dropping a tier without it.

Why long sessions are the real cost

The eight-turn figure is a polite visitor. Run the same agent for longer and the cost does not grow in a straight line, because each turn pays again for every turn before it.

8 turns, uncached Opus 5.5the worked example
$0.59
12 turns1.5x the turns, 2x the cost
$1.22
30 turnsabout 1.4M input tokens
$5.94
60 turnsone script, one session
$21.56

A real visitor rarely goes past fifteen turns. A script does not get bored. If your chat endpoint answers anyone who loads the page, a loop that opens sessions and keeps them talking all night costs you around $2,000 per hundred sixty-turn sessions on uncached Opus. Nobody needs to be malicious for this to happen; a broken client that resends on every timeout gets there too.

The price per million tokens decides how much a normal conversation costs. The caps decide how much the worst one costs, and the worst one is the one on your invoice.

The six caps that bound it

1. A per-session token cap

Add up the billed input and output tokens per session from the usage block each response returns, and refuse the next request once the session passes a limit. Set it from the arithmetic, not from a round number: twelve turns of the example above bill about 285,000 input tokens, which is 12.5 cents on cached Sonnet 5.5, so a cap of 300,000 tokens means no session can cost much more than that. On Haiku 5.5, also cap the size of each individual request below 100,000 tokens, or the last turns of a long session are billed at the higher rate.

2. A maximum number of turns

Token caps are precise; turn caps are easy to explain to a visitor. Around twelve turns, summarise the conversation into a short brief and start a fresh context, or offer the human route: a contact form or a booking link with the transcript attached. A website agent that has not solved something in twelve turns is rarely going to on turn thirty.

3. Anonymous and per-IP limits

For signed-in users, limit the account, as the build post describes. Anonymous visitors have no account, so you need something else. Have your own page issue a signed, short-lived session token and refuse requests without one. Limit how many sessions a single IP address can start per hour, but set it generously, because an office or a mobile network puts many people behind one address. Per-IP limiting is a coarse outer fence, not the main control; the per-session cap does the real work.

ts
// Runs before every model call, on the server route that holds the key.
const LIMITS = {
  sessionTokens: 300_000,     // billed tokens, about 12 turns of the example
  maxTurns: 12,
  sessionsPerIpPerHour: 20,   // generous: offices share an address
  monthlyBudgetUsd: 300,
};

export async function guard(session: AnonSession, ip: string) {
  if (await sessionsStarted(ip, "1h") > LIMITS.sessionsPerIpPerHour)
    return { ok: false, mode: "contact-form" };
  if (session.turns >= LIMITS.maxTurns || session.tokens >= LIMITS.sessionTokens)
    return { ok: false, mode: "handoff" };   // summary + human route

  const spent = await spendThisMonth();       // summed from usage blocks
  if (spent >= LIMITS.monthlyBudgetUsd) return { ok: false, mode: "static-faq" };
  if (spent >= LIMITS.monthlyBudgetUsd * 0.8) return { ok: true, model: "cheap" };
  return { ok: true, model: routeFor(session) };
}

4. Prompt caching

Caching is a cap in disguise: it lowers the cost of every turn after the first by roughly three quarters. Keep the system prompt and tool definitions byte-identical on every request (a timestamp in the prompt quietly defeats it), and check that cache_read_input_tokens in the response is above zero before you trust any cost model. The default cache lasts five minutes, so a visitor who goes to make tea pays for one fresh write when they come back.

5. Model routing

Most turns on a website agent are routine: opening hours, which plan includes what, where a document lives. Those belong on the cheapest model that answers them well, with the frontier model kept for the turns that need judgement or take an action. How to decide which calls earn the expensive model, and why caching should come first, is the whole of not every call needs the expensive model. For this post the point is narrower: routing changes the price column you multiply by, and the caps above still decide how many tokens you multiply.

6. A monthly budget kill switch

Every cap above assumes you predicted how the cost would go wrong. The monthly budget assumes nothing. Sum spend from the usage you already record, alert at 80%, and at that point move every new session to the cheap model. At 100%, switch the agent off gracefully: a static FAQ and a contact form, not an error. Then set a spend limit at the provider as well, below what would actually hurt, so a bug in your own counter cannot be the only thing standing between you and the invoice.

What I would do before launch

  1. 1Price one realistic conversation with your own prompt size, retrieval size and tool calls, using the provider's current price page. It takes ten minutes and replaces every guess.
  2. 2Turn on caching and confirm it is being read.
  3. 3Set the per-session token cap and the turn cap from that arithmetic.
  4. 4Issue anonymous session tokens from your own page, with a generous per-IP fence around them.
  5. 5Route routine turns to the cheap model once you have an eval that shows it copes.
  6. 6Wire the monthly budget to an alert, a cheaper mode and a graceful off switch, plus a provider-side spend limit behind it.

Done in that order, the per-conversation cost becomes a number you chose rather than one you discover. That is also the honest way to compare against a vendor plan: multiply your cached cost per conversation by your traffic, add the cost of the caps, and see which side of the flat fee you land on.

If you want an agent on your site with these limits built in from the first deploy, tell me what it needs to answer, what it is allowed to do and roughly how many visitors it will meet. I will price the conversation with you before any code is written. Get a fixed-scope integration quote.

Questions people ask

How much does an AI agent on a website cost per conversation?

Between a fraction of a cent and about 60 cents for a typical eight-turn conversation, depending mostly on the model and whether prompt caching is on. On Anthropic's prices as of 23 November 2026, my worked example costs $0.59 on Claude Opus 5.5 uncached, $0.16 cached, $0.08 on Sonnet 5.5 cached and under half a cent on Haiku 5.5 cached. Long sessions cost disproportionately more, which is why a per-session cap matters more than the model choice.

Why is my AI chatbot API bill higher than the token count suggests?

Because the API is stateless, so every turn resends the system prompt, tool definitions, retrieved documents and the full history. A conversation that shows 2,700 output tokens in the transcript can bill over 130,000 input tokens. Tool calls add a second request inside the same turn, and regenerate buttons, double submits and client resends add whole extra requests.

How do I stop anonymous visitors running up my AI chatbot costs?

Issue a short-lived session token from your own page, cap tokens and turns per session, limit how many sessions one IP address can start per hour, and put a monthly spend ceiling in front of everything. Per-IP limits on their own are not enough, because offices share one address and abusers have many, but as an outer fence for visitors with no account they are worth having.

Does prompt caching reduce the cost of a website chatbot?

Yes, usually by more than switching to a cheaper model. In my worked example caching cut an eight-turn Opus 5.5 conversation from 59 cents to 16 cents, a 73% reduction, because most of each request is the same prefix and conversation history the previous request already sent. The default cache lasts five minutes, so a visitor who pauses longer than that pays to write the prefix again.

How do I integrate an AI agent into a website without a surprise bill?

Price one realistic conversation before you build, then enforce the limits on the server route that holds the API key: a per-session token cap, a maximum number of turns, rate limits for anonymous visitors, prompt caching, a cheaper model for routine turns, and a monthly budget that switches the agent to a cheaper mode or a contact form when it runs out.

Building something like this?

I design and ship these systems for clients: retrieval over private data, agents that complete real tasks, and the Laravel platforms underneath them.

Keep reading