# 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.

URL: https://www.back4app.com/blog/where-ai-credits-go-token-count
Published: 2026-11-07 · Tested: 2026-10-27
Tested on: 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
Publisher: Back4app Engineering

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.

## 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](/blog/blog-assets/what-the-tokens-went-on/token-count.png)

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.

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:

```text
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:

```js
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));
});
```

## 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:

```text
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](https://github.com/templates-back4app/cost-lab) — both versions, the eleven checks they both pass, the token count by file, and the four mistakes with which ones the tests notice.
