Usage & Cost: Reading the Token Panel
Usage & Cost: Reading the Token Panel
Doforu runs on your own API key, so every token you spend is billed by the model provider directly — Doforu never marks it up. That makes two questions worth answering precisely: how much am I spending, and how much of that is avoidable.
The Usage panel answers both, and the second one is where prompt caching shows up.
Where the numbers live
Settings → Usage. Six summary cards — total tokens, input, output, call count, cache hit rate, cache hit tokens — plus a per-day stacked chart of input, output, cache hits and cache misses. Switch the period to recompute.
The bottom bar. A compact readout for the current session, including a live cache hit rate, colour-coded green at 90% and above.
The local database. Everything is in agent.db in the app data directory, table usage_records. One row per LLM call:
| Column | Meaning |
|---|---|
prompt_tokens |
Total input tokens |
completion_tokens |
Output tokens |
cache_hit_tokens |
Input served from the provider's prompt cache |
cache_miss_tokens |
Input processed fresh |
duration_ms |
Wall time for the call |
How the cache hit rate is computed
cache hit rate = cache_hit_tokens ÷ (cache_hit_tokens + cache_miss_tokens)
It is a share of input tokens only. Output is never cached, so including it would hide the thing the number is trying to tell you.
Providers report cache usage in three different shapes, and Doforu normalises all of them:
- OpenAI-compatible —
prompt_tokens_details.cached_tokens - DeepSeek —
prompt_cache_hit_tokensandprompt_cache_miss_tokens - Anthropic — input split into uncached, cache-write and cache-read buckets, which get summed back into "total input" before the ratio is meaningful
Why the rate is usually high in agent work
Agent loops append to the context; they do not rewrite it. The system prompt, the tool definitions and every earlier turn stay byte-identical from one call to the next, which is exactly the shape a prefix cache wants. In practice each turn bills full price only for what it just added.
A measured example from continuous local use — 26,732 calls over seven days on DeepSeek-V4.1-Flash:
| Metric | Value |
|---|---|
| Input tokens | 3.24 billion |
| Cache-hit input | 3.20 billion |
| Cache-miss input | 27.2 million |
| Hit rate | 99.2% |
| Average input per call | ~122,000 tokens |
| Average fresh input per call | ~1,035 tokens |
At DeepSeek-V4.1-Flash off-peak rates ($0.003 cache hit vs $0.15 cache miss per million) the caching turned a ~$484 input bill into ~$14 for the same token volume.
These figures are the app's default seven-day view in Settings → Usage, so you can reproduce them on your own install. The first day after installation is excluded: it only captures setup traffic at a fraction of normal volume, and steady-state behaviour is what the number is for.
We published the full write-up separately, benchmarked against the published results on agentic caching: Prompt Caching in Agent Workloads.
When the rate drops
A low number is not a bug. Expect it when:
- The session is short. The first call of a session has nothing to reuse beyond the system prompt. Single-call sessions routinely read 0–40%.
- You inject something large. Reading a big file or returning a huge tool result spikes the fresh portion for that turn.
- The prefix changes. Editing the system prompt, switching models, editing a tool definition or reordering the tool list invalidates everything behind it. Prompt structure is a cost decision.
- The provider does not report cache fields. Self-hosted inference stacks often don't.
What Covers X% of input means
Sometimes part of the input comes back with no cache fields at all. The rate is then computed over a partial denominator, which reads high — the missing tokens might have all been misses.
When that happens the panel shows a coverage badge instead of quietly reporting a flattering number. Treat Covers 62% as "this rate is not comparable to one at 100% coverage."
Likewise, when a provider reports nothing at all, the rate shows —, not 0%. Those two are different problems and the panel keeps them apart.
Querying it yourself
-- Overall hit rate
SELECT
COUNT(*) AS calls,
ROUND(100.0 * SUM(cache_hit_tokens)
/ (SUM(cache_hit_tokens) + SUM(cache_miss_tokens)), 2) AS hit_rate_pct
FROM usage_records;
-- Per-day
SELECT date(created_at / 1000, 'unixepoch', 'localtime') AS day,
COUNT(*) AS calls,
ROUND(100.0 * SUM(cache_hit_tokens)
/ (SUM(cache_hit_tokens) + SUM(cache_miss_tokens)), 2) AS hit_rate_pct
FROM usage_records
GROUP BY day
ORDER BY day;
Estimating what you owe
Token counts in the panel are exact; dollar amounts are not tracked, because pricing belongs to the provider and changes without notice. To estimate:
cost = cached_input_M × hit_price_per_M
+ fresh_input_M × miss_price_per_M
+ output_M × output_price_per_M
Pull the three rates from your provider's current pricing page. If your provider bills peak and off-peak differently (DeepSeek does — peak is 2× off-peak), split the window accordingly.
Reducing cost
In rough order of payoff:
- Keep sessions alive. A long session amortises the system prompt and tool definitions across thousands of calls.
- Don't edit the system prompt mid-session. It is the largest shared prefix you have.
- Stay on one model within a task. Switching models throws away the warm cache.
- Trim tool results before they enter context. A 20,000-token file read that you only need one line from is pure fresh input.
- Disable tools you are not using. Smaller tool definitions mean a smaller miss on every call.