Tokens, not letters: what a model really sees when it counts

APIClaudeKeyFree · Updated 2026-11-24 · 10 min read

An abacus next to a laptop on a desk
Counting needs a running tally, something a model does not keep by default.

It is one of the most shared screenshots in any AI community: a model that writes working code, explains tax rules and drafts a contract, yet insists a short word contains the wrong number of a given letter, or loses track of how many items are in a list it just produced. Developers often report the same thing in production, when a feature that relies on exact counts quietly returns numbers that are off by one or two.

This article is for builders who need reliable counts, lengths and tallies from a product that uses a chat model, whether that model is Claude, the free free-ai endpoint on this site, or anything else. You will learn why the mistake happens, which tasks are risky, and how to restructure the work so the model does the language part and ordinary code does the arithmetic.

Frequently asked questions

What is a token?

A token is the unit a language model reads and writes. It can be a whole common word, part of a rarer word, a punctuation mark or a run of spaces. Text is split into tokens before the model sees it, so the model never receives individual letters unless a word happens to be split that finely.

Why is counting letters hard if the model can spell?

Spelling a word out is a task the model has seen many examples of, so it can often do it well. Counting requires holding a running total across many steps without writing it down. If the model answers in one shot, it has to estimate from a compressed representation, and that estimate is frequently wrong.

Do bigger models count correctly?

Larger and newer models make fewer counting errors, and reasoning modes help further, but none of them guarantee exact results on long inputs. Treat improvements as lower error rates, not as a promise that the problem is solved.

How does counting words differ from counting letters?

Words are closer to tokens, so short word counts are usually more accurate than letter counts. Errors grow with length: a model may count a ten-word sentence correctly and miss by several on a paragraph of two hundred words.

Does turning on reasoning fix counting?

It often helps, because the model can write intermediate steps, such as numbering each item. It costs extra tokens and time, and the steps themselves can still contain slips, so for anything that must be exact, code remains the better tool.

Which is better for exact counts: the model or a script?

A script, every time. String length, word splits and list lengths are trivial in any programming language and are deterministic. Use the model to decide what to count or to interpret the result, not to perform the tally.

Is the free-ai model better or worse at counting than Claude?

free-ai is a mid-sized open-weight model of about 35B parameters, and on fiddly counting and arithmetic it is generally less reliable than the strongest commercial models. The fix is the same for both: move counting into code.

Why does the model give a confident wrong number?

Language models produce the most plausible continuation, and a specific number sounds more plausible than a hedge. Confidence in tone is not a signal of accuracy, which is why exact values should be verified outside the model.

What the model actually receives

Before any model reads your prompt, a tokenizer converts the text into a sequence of integer IDs. Common English words are often a single token, while unusual words, names, code identifiers and words in less common languages get split into several fragments. The model works entirely with those fragments. It has learned a lot about which letters tend to appear inside each fragment, but that knowledge is indirect.

When you ask how many times a letter appears in a word, the model has to recall the spelling of each fragment and add up occurrences, all inside one forward pass if it answers immediately. That is very different from how a person or a program solves the problem, and it explains why errors cluster around words that are split unusually.

Fragments hide the letters

A word stored as two tokens gives the model two opaque units. It may know the spelling of each, but the joins between fragments are where double letters and repeated characters tend to get lost.

Different models, different splits

Every model family uses its own tokenizer. A prompt that one model counts correctly may fail on another simply because the word is cut in a different place.

Why running totals break down

Counting is a sequential task: look at an item, add one, move on, remember the total. A model generating a single answer token has no scratchpad unless it writes one. It must compress the whole sequence into an internal representation and read a number off it. For short inputs that works surprisingly often; for long inputs the representation is too blurry to give an exact figure.

This is also why models struggle with tasks that look unrelated, such as keeping a list to exactly twelve items, writing a paragraph of exactly fifty words, or reporting how many rows a pasted table has. All of them need precise bookkeeping that the architecture does not naturally provide.

Length makes errors grow

Error rates rise with the size of the input. A common pattern is accurate answers on tiny examples, followed by drift once the text spans several paragraphs or the list passes a few dozen entries.

Generated lists are not tracked

When a model writes a list, it does not keep an explicit counter. Asking for twenty ideas and receiving eighteen or twenty-two is normal behaviour rather than a sign of a broken model.

Wooden tiles grouped into clusters with string
Tokenizers bundle letters into chunks, so the model sees groups rather than single characters.

Tasks where this bites in real products

Most counting failures are harmless in chat, but they cause real bugs once a model is part of a pipeline. Developers commonly discover the problem only after a downstream check fails or a user spots an inconsistency.

The risk is highest whenever a number produced by the model is treated as data rather than prose.

Length limits in marketing copy

Ask for a headline under sixty characters and you will often get one that is close but over. Generate several candidates and filter them with code, rather than asking the model to self-check.

Extraction totals

If you ask a model to read a report and say how many incidents it lists, ask it to return each incident as a separate item instead, then count the items yourself.

  • Character limits for ad copy, SMS or meta descriptions, where the model claims the text fits but it does not.
  • Word counts for essays, product descriptions or translation quotes.
  • Tallies of items, rows or mentions extracted from a document.
  • Scoring rubrics that ask the model to count criteria met and add points.
  • Pagination or chunking logic that trusts the model to split text into equal parts.

The reliable pattern: model extracts, code counts

The most robust fix is a division of labour. The model handles the parts that need language understanding, such as deciding what counts as an incident, a mention or a qualifying word. Your code handles everything that is pure arithmetic. In practice this means asking for structured output, usually a JSON array, and computing lengths and totals after parsing it.

The example below asks the free endpoint to list product names found in a text, then counts them in Python. It works the same way with any OpenAI-compatible backend; only the base URL and model change.

Ask for items, never for totals

A prompt that says list every match is far more reliable than one that says how many matches are there. The list can be checked; the total cannot.

Validate the structure

Parse the output and reject it if it is not valid JSON. A retry with a reminder of the format usually fixes the occasional malformed reply.

from openai import OpenAI
import json

client = OpenAI(base_url="https://api.apiclaudekeyfree.com/v1", api_key="none")

text = "We sell the Atlas desk, the Atlas chair, the Nova lamp and a Nova shelf."
resp = client.chat.completions.create(
    model="free-ai",
    messages=[
        {"role": "system", "content": "Return only a JSON array of product names found in the text."},
        {"role": "user", "content": text},
    ],
    temperature=0,
)
raw = resp.choices[0].message.content.strip()
items = json.loads(raw[raw.find("["): raw.rfind("]") + 1])
print(items)
print("count:", len(items))  # counted by Python, not by the model
Marbles being sorted into small bowls
Ask the model to sort items out; let code count what lands in each bowl.

Prompting tricks that help when code is not an option

Sometimes the count has to happen inside a conversation, for example in a chat assistant answering a user directly. You can reduce errors by giving the model a way to keep a visible tally. Asking it to number each item as it goes, or to spell a word with separators before counting, turns an invisible running total into written steps.

These techniques lower the error rate but do not remove it. They also lengthen the answer, which matters if you pay per token or work under a daily limit such as the 10,000,000 tokens per IP on this site's free endpoint.

Spell it out first

For letter counts, ask the model to write the word one letter at a time, separated by spaces or hyphens, and only then report the count. Each letter becomes its own token, which removes most of the ambiguity.

Number the items

For lists and sentences, ask for numbered output. The final number becomes the count, and a reader can see immediately if the numbering skipped or repeated.

Reasoning modes and their trade-offs

Many providers now offer a mode where the model thinks before answering. On the free endpoint you enable it with "reasoning": true in the request body and should allow at least 2,000 tokens for max_tokens, because the thinking itself consumes output. Claude offers its own extended thinking options; check Anthropic's documentation for how they are configured and billed.

Reasoning helps with counting because the model can enumerate items before answering. The cost is time and tokens, and the gain is not a guarantee. For a user-facing assistant that occasionally gets a counting question, it can be worth it. For a batch job that needs exact figures on thousands of records, code is cheaper and correct by construction.

When reasoning is worth it

Use it for mixed problems where some judgement is required, such as counting only the sentences that make a specific claim, and where an occasional mistake is acceptable.

When it is wasted effort

Pure length checks, character limits and row counts gain nothing from reasoning. A one-line function call is faster than any model and never wrong.

A notebook with tally marks and a clicker counter
Visible step-by-step tallies reduce mistakes when counting must stay inside the chat.

Testing for counting errors before users find them

If a feature depends on counts, add a handful of fixed test cases with known answers and run them whenever you change the prompt or the model. Include short and long inputs, words with repeated letters, and lists of different sizes. A small, boring test file catches most regressions, and the approach is described in more detail in our guide to regression tests for prompts.

Record the failure rate rather than a single pass or fail. Language models are probabilistic, and a test that passes nine times out of ten tells you something different from one that always passes.

Use temperature zero for tests

Setting temperature to zero makes outputs more repeatable, which makes it easier to notice when a change in prompt or model actually changed behaviour.

Track the margin of error

For word counts, log how far off the model was, not just whether it was right. Being off by one on long text may be acceptable for a draft; being off by twenty is not.

Choosing a model for number-heavy work

If your application is mostly about numbers, such as invoices, measurements or scoring, model choice matters less than architecture. Even the most capable commercial models, including Claude's top tiers, benefit from having arithmetic moved into code. That said, they do make fewer slips in the language-heavy parts, and where accuracy matters a stronger model clearly wins over a mid-sized open one.

A practical approach is to route cheap, structured extraction to a smaller model and reserve a larger one for the hard interpretation steps. The trade-offs of that split are covered in when to hand subtasks to a smaller model. This site is independent and not affiliated with Anthropic; free-ai is a separate open-weight model, not Claude.

Strong models still need guardrails

Better models reduce how often you need a retry, but the guardrail of counting in code costs almost nothing, so keep it regardless of which model you use.

A scale with calibration weights on a lab bench
Fixed test cases with known answers act like calibration weights for your prompts.

A quick checklist

Before shipping a feature that touches counts or lengths, run through a short list. It takes minutes and prevents the class of bugs that make users distrust an otherwise useful tool.

  • Does any number in the output come directly from the model? Move it to code if possible.
  • Is the model asked for a list of items rather than a total?
  • Is the output parsed and validated before use?
  • Are character and word limits enforced by a function, with regeneration on failure?
  • Do tests include long inputs and tricky words?
Try the free API

Send a test request to the keyless, OpenAI-compatible endpoint on the home page and see how it fits your project.

Read also