Where Your AI Credits Go: 78% of the Tokens Buy Code Every App Already Has

Credits vanish, limits arrive in days, and you pay the model to fix what the model broke. So we counted, with a real tokenizer, what the code you keep paying to regenerate actually is.

The same feature built twice and held to the same eleven acceptance checks: writing the backend yourself is 1,554 tokens of code of which 78% is the part every application has, against 332 tokens on a backend that already exists, and two of four ordinary mistakes in the hand-written version pass every test

Out of all thirteen problems in our countdown, this is the one people complain about most. Credits vanish, limits arrive in days, and somewhere in there you start paying a model to fix what it broke last round.

The usual advice is to prompt better. That is not nothing, but it misses where the money goes. Most of it is not spent on your product at all.

So we built one feature twice — once writing the backend, once on a backend that already existed — held both to the same acceptance tests, and counted the result with a real tokenizer.

Watch it instead

The price of the AI itself is number 3 in our countdown of what actually goes wrong for people building with AI.

Video: We Analyzed 130,000 Vibe Coder Posts. These Are the Problems That Actually Hurt.
Watch it instead We Analyzed 130,000 Vibe Coder Posts. These Are the Problems That Actually Hurt.
From the Back4app channel. This guide is the long version of its third position; the countdown itself is in the companion post. Open on YouTube →

What was actually counted?

The code you own in each version, after both passed the same tests:

The same feature built twice: writing the backend yourself is four files and 1,554 tokens of which 78 percent is infrastructure every application has, against two files and 332 tokens on a backend that already exists, with both passing the same eleven acceptance checks

The feature is deliberately ordinary: accounts, sign-in, and private notes that only their owner can read, change or delete. The eleven checks include a second user trying to read, and then delete, the first user’s note.

That order matters. The comparison would be worthless if one version were simply doing less, so the tests run first and the counting happens only after both pass.

What is the number actually measuring?

The artifact, not the conversation — and we want to be exact about that, because the difference is where most of the honest objection lives.

What you pay for is the whole exchange: the prompts, the model’s reasoning, the attempts that did not work, and the file being read back into context on every single edit. The tokens you spend are some multiple of the tokens in the file.

Whatever that multiple is, it is being applied to a file that is 78% the same in every application ever written.

The count is also conservative. The hand-written version we measured is compact and correct, with no dead code and no defensive sprawl. The generated equivalents we have read are longer.

Where did the 78% go?

Into four files, three of which have nothing to do with notes:

file                     what it is        lines  tokens
from-scratch/auth.mjs    infrastructure       38     507
from-scratch/db.mjs      infrastructure       23     167
from-scratch/notes.mjs   your product         25     340
from-scratch/server.mjs  infrastructure       35     540
total                                        121    1554

Password hashing with the right cost parameters. A constant-time comparison. Session tokens with real entropy. A schema. HTTP routing, body size limits, error mapping. None of that is your app; it is the floor every app stands on.

The other version is a schema with its permissions, and five lines saying whose row is whose:

Parse.Cloud.beforeSave('Note', (req) => {
  if (!req.user) throw new Parse.Error(119, 'sign in first');
  if (!req.object.existed()) req.object.setACL(new Parse.ACL(req.user));
});
The same feature, the same eleven tests
1,554tokens of code written by hand
→
332tokens on a backend that exists
78%of the first one is the part every app has
Counted with gpt-tokenizer. Identical across two runs.

Why does the same bug keep coming back?

Because it lives in the part you keep regenerating, and your tests mostly cannot see it. We took four ordinary mistakes, applied each to a copy of the hand-written version, and ran the same eleven checks:

the mistake                       caught by the battery?
password compared with ===        NO — all 11 checks still pass
session token from Math.random()  NO — all 11 checks still pass
no ownership check when reading   yes — "you cannot open someone else's note by id"
no ownership check when deleting  yes — "you cannot delete someone else's note"

Two of four ship. And the two that ship are the two you would least want to: a password comparison that leaks timing, and session tokens anyone can guess.

None of the four is possible in the version that does not write that code. Not because it is better code — because it is not your code.

So what should the tokens go on?

Your interface and your logic, which is the only part that is actually yours. When accounts, the database, permissions and APIs already exist, the prompts that would have produced them simply never happen.

That removes two costs at once. The rounds spent generating infrastructure, and the rounds spent fixing what those rounds got subtly wrong — which, on the evidence above, you would not have noticed for a while.

What should you do first?

Before your next big prompting session, write down the acceptance checks for the feature. Not tests in a file, necessarily — just the list of things that must be true, including what a second user must not be able to do.

Then look at what you are about to ask for and mark which parts are the same in every app ever built. That is the part to configure rather than generate, and it is where most of the budget was going.

The lab is in the repo — both versions, the eleven checks they both pass, the token count by file, and the four mistakes with which ones the tests notice.

Tagsai-codingcosttokensbackendvibe-codingauthentication

Frequently asked questions

Why do my AI coding credits disappear so fast?

Because a large share of them goes on code that is the same in every application. We built one feature two ways and counted with a real tokenizer: writing the database, sign-in and server by hand came to 1,554 tokens of code, of which 1,214 — 78% — was infrastructure rather than anything specific to the product.

How much code does a managed backend actually save?

In our measurement, 4.7 times less to produce and maintain: 121 lines across 4 files against 27 lines across 2, for a feature that passes the same eleven acceptance checks either way. That is a conservative figure, because the hand-written version we measured is compact and correct, and generated ones are usually longer.

Does counting tokens in the code tell me what I spent?

No, and we are careful about that. The code is the artifact; what you pay for is the conversation — prompts, reasoning, failed attempts and the file being re-read on every edit. The count tells you what the spending is on rather than how much it was, and 78% of that file is the part every app has.

Why do I keep paying the AI to fix bugs the AI created?

Partly because the bugs live in the code you least want to be writing. We introduced four ordinary mistakes into the hand-written sign-in and ran the same eleven tests: two were caught, and two passed everything. Both of the two that shipped were security flaws.

What mistakes get through a normal test suite?

The ones that do not change behaviour. A password compared with === instead of a constant-time comparison passes every functional test and leaks timing. Session tokens from Math.random() pass every functional test and are predictable. Missing ownership checks did get caught, because those change what a second user can see.

What should the AI be spending tokens on?

Your interface and your logic, which is the only part that is actually yours. If the database, accounts, permissions and APIs already exist, the prompts that would have produced them never happen — and neither do the rounds spent fixing what those prompts got wrong.

Further reading

Reviewed & verified by Back4app Engineering, Editorial review at Back4app

Tested Oct 27, 2026 — Local: Node 22.21.1 on macOS, arm64 · node:sqlite against Parse Server 7.4.0 with MongoDB 7 · Token counts from gpt-tokenizer · Back4app, free plan.

Changelog

  • Nov 7, 2026 — The companion repository is not published yet, so the link to it and the button were removed; they come back when it is.
  • Oct 28, 2026 — The companion repository is published, so the button and the inline link to it are back.

More from Back4app Engineering

Backend · tutorial

How to Add Authentication to a Web or Flutter App Without Writing an Auth Server [Full Repo]

Backend · report

Why Vibe-Coded Apps Break: 13 Problems From 130,000 Posts, Ranked, With the Fix for Each

Backend · tutorial

Your Frontend Talks Straight to the Database. Here Is How to Lock It Down [Full Repo]