Things to know when using AI
If you are paying for AI that charges by usage, you need to know a few things, or you will pay way more money to the AI provider. And I think the best way to understand the problem is to provide some examples. For this example, I will use the latest VS Code at the moment of writing, and I will use the ChatGPT 6 Luna model at Medium reasoning. It costs $0.1 for 1M input tokens and $0.5 for 1M output tokens.
Let's say you have a question: “What is the capital of France?” You typed it in, and AI answered: “Paris.” Let's see what that costs us. The number of input tokens will be 7; the number of output tokens will be 2. So you would multiply and get $0.0000007 and $0.000001 and get $0.0000017. Wow, this is extremely cheap, isn’t it?
Well, I’m sorry to tell you, but the real picture will be quite different. Instead of 7 tokens, VS Code will send 6,705 tokens. It will include the system prompt (be polite, no racism, etc.), available tools, the environment context (location of your workspace, session memory, repo memory, etc.), and the current date. So you will pay an extra $0.0006698, or 958 times more than you expected.
Then you will not receive 2 tokens. Instead, you will receive 6 because of internal formatting. But it is only the visible portion. The model will reason about the answer, and it will produce about 64 more tokens for this. So your total price for output will be 0.000035.
But we are not finished here. The provider needs to write all input to cache. For Luna 6, it costs an extra 25% of the input price. It will write 6,656 tokens because it writes whole blocks of 128 tokens. It will cost an additional $0.00016640. So the total cost will be $0.00087190, or 512 times more than you would expect.
When you see this, it is totally ok to say something like: “Well, it is way less than one cent, so who cares?” and they would be right, but stay with me. Now let's say I type “What about England?” And AI will happily answer “London.”
Let’s see what happened here. Now VS Code will send everything above again. And I mean everything: the system prompt, available tools, environment context, your first question, and the answer to it. Plus your second question.
Some part of your second request is cached, and for Luna 6, the part that is in the cache will be charged at 10% of the input rate or $0.01 per 1M tokens. It may sound very small. But when you send a third request, you will be charged 10% again. Then again at the fourth time, fifth. You will be charged for it every single request.
So if you ask 11 questions, you will be charged the cached price 10 times for the first question, 9 times for the second question, etc. Or, in other words, you will be charged 2 times for all tokens of the initial question (your question plus all system stuff). 1.9 times for your second question + response to the question. 1.8 times for the third question, plus the response to the second question.
Of course, if you ask only simple questions, it does not really matter. But let's go to the second example. Imagine you ask: “Please create a python script for Blender 5.3 to create a tree with textures etc.” And the model will happily generate this script for you. It will output around 3500 tokens. Then you may ask for some fixes. It will produce another 3500 tokens, then again and again.
So the first question will be 6600 tokens. The response will be 3500. For the second question, you will pay 10% for 6600 and the full input price for 3500. For the third question, you will pay 10% for 10100 tokens plus the full input price for another 3500. After 10 iterations, there will be over 40000 tokens in your context.
If you want to do some agentic work, the system prompt will be even bigger because it needs to include all tools; it could be quite long. You can easily start with 10K tokens or even more. If you add or remove any tool in the middle of your session, then caching will stop working for the next request, and everything will be treated as a new super long question.
When the session becomes too big, many tools will ask AI to compact it, and it also breaks caching but saves tokens in the further requests. Sometimes it makes sense to ask AI to create a summary of work done, what needs to be done, and specifically write that you want to continue in the new session. Very often, an AI can do a better job than compacting.
You need to pay attention to these things because many developers are simply not aware of these issues and continue to work in long sessions because it feels natural to just ask one more question or ask for one more fix. But in the end, it will cost them a lot of money.
Also, you need to pay very close attention to caching prices. Some models charge way more than 10%. Some providers do not have cache at all, and as a result, you will pay for the same text over and over. Imagine you asked for 50 adjustments in the above-mentioned Python script. You will pay for 13K tokens 50 times, for 3500 49 times + 3500 48 times .. + 3500 1 time.
For the ChatGPT 6 Luna model, the price will be around $0.21 because of cache. But if there is no cache, the total price will be almost $0.6. For this model, it is still ok, but if you do the same with the top model that costs 30 times more, the price will be over $10.
But it is not all. A lot of providers have limited cache time. Sometimes it is 30 minutes, sometimes 5. Say your provider has a 5-minute timeout. The AI generated the Python script; you ran it on Blender and then started looking at the generated model. 6 minutes later, you found some issue and asked AI to fix it.
As a result, you will pay the full price for every character in your chat because the cache is gone, plus 25% of the input price to write to the cache. If you start thinking again, everything will repeat.
Last thing. Do not compare models only by the price of the input and output tokens alone. Some models like DeepSeek look very cheap on paper, but they are very chatty. And typically the output costs much more than the input. As a result, often you will pay more than using more expensive models. Sometimes much more.
What is the conclusion here? Disable tools you don’t need. Reduce the size of the system prompt. Closely monitor context size because long sessions will cost much more. When session size grows to a certain limit, compact it or ask AI to write a summary and start a new session. Test models and see the actual cost for your task.
I hope it helps someone.
Comments