Skip to content

Optimizing DeepSeek API spend

In short: I broke my DeepSeek bill down by token type, found where the money leaks, and built two indicators into OpenCode. They returned 16.5% on a workload that had grown 20%.

At the end of October DeepSeek sent an email: here is a new model, and here is the price list for it. The table had something interesting in it: there are three grades of tokens, and they cost radically different money.

Price of a million tokens: cache hit, cache miss, output Token price differs noticeably by grade

The absolute price is the less interesting part. The pattern is what matters: output costs more than input, and caching makes input 50 times cheaper. DeepSeek Pro shows the same picture, if with less dramatic proportions of 1 : 30 : 90.

I got curious: is this lever working for my budget, or against it? The budget structure report would tell me.

I already had the data: the session history OpenCode has been accumulating since June. For a cross-check, I had the usage and billing exports from the API platform. A separate access token made it easier: I didn’t have to filter other consumers out of the report.

A purpose-built prompt to the agent gave me the spend split by grade: I compared token shares with expense shares.

Token budget structure: shares of volume and shares of the bill Small shares of token volume produce noticeable shares of spending

The good news first: a huge share of cache hits already saves me about 94% of the budget — without the cache I would have paid 17 times more for the same volume. Thanks to the DeepSeek API for that, and to me for a decent instinct when setting up the workflow.

The flip side: 27% of my budget was eaten by just 1.5% of tokens that missed the cache. Let’s see whether those costs can be optimized.

Put simply, the cache is when the model “remembers” what it has read for a while, so it can “recall” it quickly (a cache hit) instead of reading it again (a cache miss).

Say I’m auditing a project for a client. The project data lives in many files and folders — briefs, research, results. I make pinpoint changes and want to check them against earlier information for contradictions. Without a cache I would either pay to re-read the whole project or batch the edits — and work slower. The cache solves this: the model keeps the current context without a significant overspend. I make changes one at a time in a long session; that’s how I like to work.

The cache has no hard expiry: DeepSeek doesn’t disclose it, and some sessions survived with the whole cache intact for two or three days. But the chance of finding the cache cold grows with idle time. From the session history I got a curve with two thresholds: by the fourth hour of idle time the cache is intact in 96% of calls, by the ninth in 80%, and after that it drops sharply.

The other side of the question is answer quality. Colleagues report it degrades noticeably once the context reaches 20–30% of the stated window. A long session is convenient for the human, but the model starts to slip.

I’m gradually embedding AI into my workflows: code, the knowledge vault, writing, data. The more workflows, the more calls and tokens. From July to October, tokens per day grew 2.8 times, calls per day 1.8 times, and context per call 1.6 times.

Average token spend per active day, June–November 2026 Token spend grows as AI spreads into my workflows

As long as the monthly bill stays within $12, it feels like nothing to worry about. But at that trend, in a few months I’ll hit $50 — and prices are not forever: they have changed a couple of times this year already.

Roughly half of the growth is more calls, the other half is more context per call. The context problem will only grow.

Six tenths of the bill is input tokens, and they are not paid once: every step pushes the whole session history through the model again. The longer the history, the more expensive the next step. I won’t cut calls — that is the work. I can’t change the token price — the provider sets it. But the length of the history is mine to choose.

And my working pattern was hitting exactly that spot. I kept a dozen tabs open in OpenCode and returned to them when needed. Sessions hung for days until the context grew to 600–900k — where the drop in quality is already obvious.

Everything pointed to the same move: stop keeping sessions open for days and softly cap context length at 250k, a quarter of DeepSeek Flash’s 1M window.

Hypothesis: if I don’t revive sessions after ten hours of idle time and keep context under 250k, the bill will drop 10–20% and answer quality won’t degrade.

To test it with data, I had to change my usual way of working.

To stop reviving stale sessions, I needed two breakpoints in the usual flow: a quick way to spot a “stale” session and a cheap way to compact it without losing the thread. I made two changes to the interface.

  1. A timer in the header next to the context and cost counters, showing the time since the last turn. After 4 hours it becomes more prominent and gradually turns red until 10 hours — and only if the context is over 50k. On a small session a cold start costs pennies.

  2. A pill above the composer. It shows how full the “zone of good answers” is — the first quarter of the context window; once that is exceeded, it turns into a compact button.

Idle timer in the header and context pill above the composer Two changes: a timer in the header and a pill above the composer

Together they make one scenario. Red — start a new session. Yellow — compact. Leaving your desk — compact with the pill while the cache is still warm.

I also built automatic compaction on a timer so I wouldn’t have to keep the routine in my head. I tried it: it didn’t fire with the laptop lid closed, and later it interrupted another intention of mine at a bad moment. I rolled it back.

A few days later I compared like with like: 2–5 November before the switch and 9–12 November after. I dropped the launch day itself — automatic compaction woke old contexts and ran up a spike in spend.

MetricBeforeAfterΔ
Calls per day204244+20%
Tokens per day31.4M24.5M−22%
Tokens per call154k101k−35%
Money per day, DeepSeek actual$0.376$0.314−16.5%
Money per call, actual$0.00185$0.00129−30%

What I concluded from the data:

  • More work, a smaller bill: every call got almost a third cheaper. That is inside the promised 10–20%. The money hypothesis holds.
  • In the nine days after the switch there was not a single return to a cooled-down session. On such a short horizon that is not proof yet — more a first confirmation.
  • The cache is the cleanest part of the test. Before the switch, 84% of my returns to a session after ten hours of idle time lost the cache; after the switch there were no such returns at all.

Two caveats:

  • The numbers come from both changes at once, because they work as one scenario; I don’t see the point in separating them.
  • Quality rests on indirect signals: the context never entered the degradation zone, and subjectively nothing got worse. I didn’t set up a strict metric here.

An interesting observation about the dollars in the interface: OpenCode shows an estimate up front, while DeepSeek bills some calls at half price. Over a full week the actual turned out to be almost half of the interface figure. It doesn’t affect the percentages in the calculations, it just adds a little noise.

The 16.5% saving came to about $2 a week at the current volume. My bet is that as consumption and token prices grow, the sum will become more noticeable.

I have ideas for the next notes:

  • Make the soft cap smart, so the model decides.
  • Look into the cache in Claude Code: the model is more expensive, so the problem is sharper.
  • Work out how to save on output tokens.

If your AI bill grows faster than your tasks and you can’t tell where the tokens go, message me on Telegram, by email, or pick a time for a call. Let’s figure it out.