Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Claude from Zero to Expert Class #94: Calculating Costs and Tokens”.
Other ways we can help with Claude.
Learn with a mentor
Scheduled AI & Machine Learning courses with live guidance and a certificate.

Midjourney Course: Create Stunning AI Images from Text
★ 4.9

DALL-E Course: Creating Professional AI Images from Text
★ 4.9

Stable Diffusion Course: AI Art from Beginner to Professional
★ 4.9
Have it built for you
No time to learn Claude? Our team can do the project for you.

AI Image Creation with Stable Diffusion — Unlimited Custom Visual Production
★ 4.9

AI Image & Video Creation with Leonardo AI — All-in-One Visuals for Business
★ 4.9

AI Image Creation with Midjourney — Cinematic AI Art for Business
★ 4.9
Get notified about new Claude classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
Hi, and welcome back. The Telegram bot and the Sunset Coffee review flow are running. The next question is sure to come from Laras: how much does it cost? In this episode we calculate costs from tokens, log real usage, then learn five ways to save and how to set up cost guardrails.
Every time the bot answers, what gets sent to Claude? First, the system instructions. They're sent every single time, even though they don't change. Second, the content of the shop info file: the product list, prices, opening hours, and shipping. The bot needs this data to answer correctly. Third, the conversation history, so the bot remembers earlier questions. The longer the chat, the more tokens get sent along. Fourth, the customer's question itself. Funnily enough, this is usually the shortest part. Fifth, Claude's answer. The first four parts count as input tokens, while the answer counts as output tokens, at a different rate. So if you want to save, don't just ask customers to keep their questions short. The parts we send ourselves every time are far bigger and much easier to control. Raka uses the test script from the start of the session to measure one question. The result: about one thousand one hundred fifty input tokens. The answer is only about eighty output tokens, because the instructions limit answers to three sentences. And about ninety-three percent of the input tokens are parts sent over and over: the instructions and the shop data. That's our main target for saving later. Your numbers will be different, so measure your own.
Let's do the math. Important: the rates in this table are example numbers, rounded on purpose, not official prices. Say input tokens cost twenty rupiah per thousand tokens. One thousand one hundred fifty tokens comes to about twenty-three rupiah. Say output tokens cost more, one hundred rupiah per thousand tokens. Eighty tokens comes to eight rupiah. Notice that even at the higher rate, the cost is small because the answer is short. The total is about thirty-one rupiah per question. The formula is always the same: input tokens times the input rate, plus output tokens times the output rate. Official rates are usually listed per million tokens, in dollars, and they differ for every model. Take the numbers from Anthropic's pricing page, then plug them into the same formula. Now a one-month simulation. Say the bot gets one hundred questions a day. One hundred times thirty-one rupiah is about three thousand one hundred rupiah a day. Times thirty days, that's about ninety-three thousand rupiah a month, still using example numbers. This number needs to be weighed against the benefit. If the bot saves Dimas an hour of work every day, Laras can judge for herself whether it's worth it. What matters is that the decision is based on math, not guesswork. Don't forget the review flow in n8n. The math is the same: how many reviews per day, how many tokens per review. Since reviews are far less frequent than questions, the cost is usually much smaller than the bot's.
Estimates need to be checked against reality. Raka asks Claude Code to log the usage of every answer to a log file. Notice his last sentence: don't save the content of customer messages. Claude Code reads the bot file first. The change is just three green lines. It turns out every API response already carries token usage numbers, so the bot just needs to log them. Raka reads the change, then approves it. Claude Code confirms that only numbers and times are logged. Customer privacy stays protected, and the log is still useful. After three days, Raka opens the log in Google Sheets. Day one: eighty-six questions. The cost column uses a formula with the example rates from before. Day two: one hundred twelve questions. Day three jumps to one hundred forty-three, and input tokens rise even faster. It turns out some customers had long chats, so the conversation history swelled too. The average is about one thousand two hundred eighty input tokens per question, a little above the estimate. That's why we log: real numbers often differ from the first calculation. Also compare them with the usage report in the Anthropic console.
Now, five ways to save. First, choose a model that fits the task. Answering opening hours doesn't need the biggest model. Compare each model's rates on the pricing page, then test whether a lighter model is good enough. Second, trim the parts that get sent over and over. Tight instructions and shop data without filler sentences can cut hundreds of tokens from every question. Third, limit answer length with a token limit and a request for short answers. Fourth, limit the history. The bot doesn't need to send the whole chat since the morning; the last few messages are usually enough. Fifth, use official savings features, such as prompt caching. It temporarily stores the parts of a prompt that never change, so they're cheaper when sent again. Check the official documentation for the conditions and the size of the discount. Raka applies two methods at once: limiting history to the last six messages, and enabling prompt caching as the documentation describes. He also asks for a retest. Claude Code changes the bot file as requested. Then it runs the ten test questions saved since the bot episode. All of them still match what's expected. This is the key to saving: quality must hold. Savings that make the bot answer wrongly end up costing more, because customers get disappointed and Dimas has to fix things. A week later, Raka compares the logs. The difference is in the history: before, the whole chat was sent; now, only the last six messages. With the same example rates, the cost per question drops from about thirty-four rupiah to about twenty-five rupiah. At an average of one hundred fourteen questions a day, the monthly estimate drops from about one hundred fifteen thousand to eighty-six thousand rupiah. That's roughly a quarter saved, without sacrificing answer quality. Your savings will surely differ, depending on the model, the latest rates, and how your customers chat. What's worth copying is the method: change one thing, measure from the log, compare, then decide.
Finally, set up cost guardrails. First, a monthly spending limit in the Anthropic console. The menu location can change, so follow the official documentation. Second, automatic alerts when usage nears the limit, so you know before it's too late. Third, a per-user daily message limit in the bot. One prankster sending thousands of messages can burn through the budget overnight. Fourth, check the token log every week. A sudden spike is a sign that something needs checking. Fifth, prepare a fallback message. When the limit is reached, the bot doesn't go silent; it politely sends customers to Dimas. For your business, write these five guardrails in one note, with the limit numbers and who checks the log each week. A guardrail without an owner usually gets forgotten.
We calculated costs from tokens with example numbers, logged real usage without saving message content, applied savings while keeping quality, and set up cost guardrails. Real rates always come from Anthropic's official pricing page. Cost guardrails are only half the story. In the next episode we cover security: prompt injection, which means messages that try to hijack the bot, and how to limit agents. See you there!
Try these on your own after watching to lock in what you learned.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →