How to track what AI costs, per task
The monthly invoice from an AI provider tells you what you spent. It does not tell you which task, client or automation spent it.
Short answer
Record every model call against the job that made it, with its input tokens, output tokens and the model's price at the time. Cost = input tokens × input price + output tokens × output price. Add the calls up per task, client or automation. Record calls with no known price as unknown rather than free, and set a limit before anything runs unattended.
Why the monthly bill is not enough
- One key, many jobs. Most offices use one API key for everything, so the bill cannot separate the client summaries from the experiments.
- You cannot price the work. If an automation saves two hours a month, you need to know whether it costs 40 cents or 40 euros to run.
- Runaways show up late. A task stuck in a loop, or sending a whole document when a paragraph would do, appears as a spike at month end — after the money is spent.
How token pricing works
Providers charge per token — a chunk of text. In English, one token is roughly four characters, or three-quarters of a word. Prices are quoted per million tokens, separately for input (what you send) and output (what the model writes). Output is usually several times dearer than input. Some providers discount repeated input that they cache, and models that "think" before answering bill that thinking as output.
A worked example, with made-up prices of $1 per million input tokens and $5 per million output tokens:
| Tokens | Price per million | Cost | |
|---|---|---|---|
| Input | 6,000 | $1.00 | $0.006 |
| Output | 800 | $5.00 | $0.004 |
| One run | $0.010 | ||
| Every weekday for a year (≈260 runs) | ≈$2.60 |
Real prices vary by a factor of a hundred or more between models, which is why the choice of model matters more than almost anything else you do about cost.
What to record for every model call
| Field | Why |
|---|---|
| Run or job id | Ties the call to the task, client or automation that made it |
| Provider and model | Prices differ by model, not just by vendor |
| Input and output tokens | The two quantities you are billed for |
| Price used, and its date | Prices change; last month's cost should use last month's price |
| Cost — or "unknown" | A missing price must not read as $0 |
| Duration and outcome | A cheap call that failed and was retried five times is not cheap |
How OpenClerq records it
- Every model call is recorded against its run — a task, a trigger firing, a webhook or a chat message — with its tokens and cost. The run list shows what each one cost.
- Unknown is not free. A model with no price in the registry is reported as unknown cost, never as $0. The gateway's
/metricsendpoint reports bothllm_cost_usd_totalandllm_unpriced_calls_total, so you can see how much of your spend is unaccounted for. - Prices are data you control. They live in the provider registry, in US dollars per million tokens. Copy it to
~/.clerq/providers.yamlto correct a price, add a model, or give your LM Studio models a price of zero so they stop showing as unknown. - Compare before you commit. The chat console's comparison mode sends one message to up to eight models and shows the latency, tokens and cost of each answer side by side. Pick the cheapest model whose answer you would accept.
- Stop spending now. Cancel a run, or use the kill switch to cancel everything and pause all triggers.
Limits today
OpenClerq 0.5 records and reports cost; it does not yet enforce a budget. Per-automation budgets that pause an automation instead of letting it overspend arrive in release 0.6. Until then, use your provider's account-level spending limits as the backstop.
Six ways to spend less
- Use the smallest model that does the job. Routine summaries rarely need the top model.
- Send less. The paragraph that matters, not the whole file.
- Cap the answer length with the max-tokens setting.
- Keep stable instructions identical between calls so providers that cache repeated input can discount it.
- Move routine, sensitive tasks to a local model, which has no per-token cost at all. See how to run AI locally.
- Do not let the model do arithmetic. Wrong numbers mean re-runs; a calculation engine is cheaper and right the first time.
Frequently asked questions
How do I calculate the cost of one API call?
Multiply the input tokens by the input price per token, multiply the output tokens by the output price per token, and add them. Prices are usually quoted per million tokens, so divide by 1,000,000 first.
What is a token?
A chunk of text the model reads or writes — a short word, part of a longer word, or a punctuation mark. In English, a token averages about four characters. Other languages often need more tokens for the same text.
Why record unknown cost separately from zero?
Because a model missing from your price list would otherwise appear free and quietly understate what you spend. Reporting it as unknown tells you to fix the price list.
Can I set a spending limit?
Most providers let you set a monthly limit or alert on your account. OpenClerq 0.5 has a kill switch that stops everything at once; per-automation budgets arrive in release 0.6.