How much does an AI chatbot cost to build and run?

An AI chatbot's monthly cost is the sum of model tokens, hosting for the process and a database for history. In an example with 9,000 conversations a month and hypothetical prices, tokens alone range from about $43 to $860, depending on the model tier.

Updated 7 min read

Learning objectives

After reading this article you will be able to:

  • Separate the cost of building an AI chatbot from the cost of running it
  • Calculate token spend per conversation, including history and RAG
  • Spot hidden costs and the ways to cut the bill
On this page

Getting an AI chatbot online is easy now: a few dozen lines of code and an API key give you a bot that answers on Discord, WhatsApp or a website. The hard part is predicting what it will cost once users arrive, because the bill is not fixed. It grows with the number of conversations, with the length of each one and with the model you pick.

The numbers in this article are hypothetical, chosen to keep the math easy, and in US dollars. They are not any provider's prices; real rates are on the official pricing pages, such as Anthropic's and OpenAI's.

input tokens per message123456message in the conversationSystem promptRAG contextHistoryQuestion
The API is stateless: every message resends the history, so the sixth one costs far more than the first.

What makes up the cost of an AI chatbot?#

There are two phases with different costs.

Building is a one-time cost: the time of whoever writes the code (or assembles the flow in a visual tool), the system prompt, testing and, if the bot answers questions about company documents, preparing the knowledge base.

Running is the monthly cost, and it is the one that surprises people:

  • Model tokens: every message calls the LLM API and pays for input and output. It is almost always the largest line. The article on LLM API cost covers how billing works.
  • Hosting the process: the bot or API that receives messages has to stay up 24 hours a day.
  • Database: to store history, users and usage limits.
  • Knowledge base (RAG): embeddings and a vector database, if the bot looks up documents. See what is RAG.
  • Channel: some channels charge on their own. The official WhatsApp Business API, for example, has its own per-message pricing; see what the official WhatsApp API costs.

How much do model tokens cost?#

Providers bill per million tokens, with one price for input and a higher one for output. The math in this article uses two round, hypothetical rates, the same as in the LLM API and RAG articles, in USD per million tokens:

Model tier Input Output
Small model (hypothetical) 0.20 1
Mid-tier model (hypothetical) 4 20

In real price lists, output usually costs several times as much as input, and a mid-tier model can cost dozens of times as much as the small one from the same provider. Check the rates for the model you will use before redoing the math. For a support chatbot that answers common questions, the small model is usually enough; test with real questions before moving up.

How do you estimate the cost per conversation?#

A chatbot does not only pay for the question and the answer. With every message, it sends:

  • the system prompt (instructions, tone, rules);
  • the knowledge base excerpts retrieved by RAG, if any;
  • the conversation history so far, because the API is stateless;
  • the new question.

That is why the sixth message in a conversation costs much more than the first. Hypothetical example: a support bot with 300 conversations a day (9,000 a month), 6 user messages per conversation, an 800-token system prompt, 1,500 tokens of RAG context per message, 50-token questions and 200-token answers.

The script below does the math and runs on any recent Node.js version:

js
// chatbot-cost.mjs: node chatbot-cost.mjs
const conversationsPerMonth = 9_000; // 300 a day
const turns = 6; // user messages per conversation
const system = 800; // system prompt tokens
const ragContext = 1_500; // knowledge base excerpts per turn
const question = 50;
const answer = 200;

// USD per million tokens: hypothetical values, swap in the provider's current prices
const models = {
  "small-model": { in: 0.2, out: 1 },
  "mid-tier-model": { in: 4, out: 20 },
};

let input = 0;
for (let t = 0; t < turns; t++) {
  // the API is stateless: every turn resends the previous history
  input += system + ragContext + t * (question + answer) + question;
}
const output = turns * answer;
console.log(`Per conversation: ${input} input tokens, ${output} output tokens`);

for (const [name, p] of Object.entries(models)) {
  const perConversation = (input * p.in + output * p.out) / 1_000_000;
  const rag = (turns * ragContext * p.in) / 1_000_000;
  console.log(
    `${name}: $${(perConversation * conversationsPerMonth).toFixed(2)} per month ` +
      `(RAG: $${(rag * conversationsPerMonth).toFixed(2)})`,
  );
}

Result:

Model Tokens per month RAG share
Small model $42.93 $16.20
Mid-tier model $858.60 $324.00

Each conversation uses 17,850 input tokens and only 1,200 output tokens. Even with output priced higher per token, input accounts for most of the bill, and almost 40% of the total comes from RAG context. These figures cover the model only, before taxes and currency conversion fees.

How much does adding a knowledge base (RAG) cost?#

RAG has three cost parts, and only one of them matters:

  1. Indexing the documents. You generate an embedding for each chunk. Assuming an embedding model at $0.05 per million tokens (a hypothetical rate), a knowledge base of 500 pages at 500 tokens each (250,000 tokens) costs $0.0125 to index.
  2. Embedding each question. In the example, 54,000 questions of 50 tokens a month add up to 2.7 million tokens: about $0.14.
  3. Sending the excerpts to the model. The 1,500 retrieved tokens go in as input on every message. That is the $16.20 or $324 line in the table above.

So the cost of RAG is in the size of the context, not in the embeddings. Retrieving 3 good chunks instead of 10 mediocre ones cuts the bill and usually improves the answer. There is also vector storage, either a dedicated vector database or a vector extension on a database you run yourself; see what is a vector database and how much RAG costs.

What hidden costs show up?#

  • Long conversations. A 20-message conversation resends the history 19 times. Without a history limit, cost per conversation grows quickly.
  • Abuse. A user can treat the bot as a general assistant and trigger huge answers. See what is prompt injection and keep max_tokens in the code, not just in the prompt.
  • Reasoning models. "Thinking" tokens are billed as output. Set a cap or turn reasoning off for simple questions.
  • Retries. Network errors with automatic retries pay for the same call twice.
  • Channel fees and currency. Paid channels bill separately, and the model invoice is in US dollars.
  • Maintenance time. Updating the knowledge base, reviewing wrong answers and switching models when the current one is retired also cost hours.

How do you keep a chatbot's cost under control?#

  1. Start with the smallest model and only move up when tests show bad answers. An alternative is routing: simple questions on the small model, hard cases on the mid-tier one.
  2. Limit the history to the last 6 to 10 messages, or summarize older ones in a sentence.
  3. Trim the RAG context: fewer, more relevant chunks.
  4. Use prompt caching when the start of the prompt repeats. A cache read usually costs a small fraction of the input price, but the cache expires after a few minutes without use.
  5. Set per-user limits: messages per day and a maximum question length.
  6. Store answers to identical questions when the content does not depend on the user, such as opening hours.
  7. Set a monthly cap in the provider's dashboard and a token counter in your code.

To get the bot online, see how to host an AI chatbot. If you want to build it without code, see how to host n8n.

How to do this on Square Cloud#

Two lines of this bill depend on where you put the bot: hosting the process and the model tokens. On Square Cloud, both can live in the same account, billed in Brazilian reais, by Pix or card.

The bot or chatbot API runs in an always-on container. Automatic restart is on by default for dashboard deploys and brings the app back when the process exits with an error. A background app uses at least 256 MB of the plan's RAM pool, and a web app 512 MB. Hobby starts at R$12.49 per month with 1 GB, and traffic is not billed by bandwidth or by request, under a fair use policy.

From Standard (R$44.99 per month) you also get MongoDB, PostgreSQL, MySQL and Redis hosting, for history and per-user limits, and the AI Gateway: an OpenAI-compatible API that gives your chatbot the cubic model, the same one behind the dashboard assistant. You point the OpenAI SDK at https://api.squarecloud.app/v2/ai and use an account API key with the ai:chat scope. The gateway is in beta, with early access at no extra cost: as long as usage fits the plan's limits, the token line in the table above does not become a dollar invoice. Limits and availability may change when the beta ends.

Redo the math with those limits before you switch providers. On Standard, the gateway accepts up to 2.5 million tokens and up to 1,000 requests a day, one request at a time; on Pro, up to 5 million tokens and up to 5,000 requests a day. The 6-message conversation in the example uses about 19,000 tokens, so Standard handles roughly 130 conversations of that size a day and Pro roughly 260. The example's 300 daily conversations call for Enterprise, with up to 10 to 20 million tokens a day. The gateway answers in text only and does not stream yet.

See the details and code samples on AI Gateway and compare plans on pricing.

AI

Host AI apps in always-on containers

Learn more

FAQs

How much does an AI customer support chatbot cost per month?

In an example with 300 conversations a day and 6 messages each, tokens cost about $43 per month on a small model and $860 on a mid-tier one, using the article's hypothetical prices. Real rates are on the provider's pricing page. Hosting and the database come on top.

Why does each message in a conversation cost more?

The model API is stateless. For the bot to remember what was said, you resend the history with every message, and those tokens are billed again as input. The sixth message of a conversation carries the previous five.

Does RAG make a chatbot much more expensive?

Embeddings are cheap: indexing a 250,000-token knowledge base on an embedding model at $0.05 per million (a hypothetical rate) costs about one US cent. What adds up is the retrieved text, which goes in as input tokens on every message.

Can I build an AI chatbot without coding?

Yes, with automation tools such as n8n, which connect the model to channels like WhatsApp and Telegram through visual workflows. Token costs stay the same, and the tool also needs to be hosted.

Next articleHow much does a RAG system cost? Embeddings, database and LLMA RAG system has three costs: embeddings, a vector database and the LLM. See the math for 1,000 questions a day, with hypothetical prices, and where the bill grows.