pi-deepseek-pricing-by-time
Time-of-day-aware DeepSeek cost accounting for pi.
DeepSeek prices every request with peak/off-peak (valley) rates that depend on the
hour of day, but pi's cost display is static: it applies one fixed rate set from the
model metadata to every message. This extension fixes that by re-pricing each DeepSeek
assistant message with the rate tier that was actually in effect when the message was
produced, so everything pi derives from per-message cost — session totals, the footer,
the statusline cost segment, /usage, exports — matches what DeepSeek bills.
How it works
- Hooks
message_end(the same event pi's own docs use for cost correction) and, for assistant messages from thedeepseekprovider, recomputesusage.costfrom the message's token counts (input,output,cacheRead,cacheWrite) using the peak or off-peak rate in effect at the message's own timestamp (UTC). - pi's session totals are the sum of per-message
usage.cost.total, so the corrected values flow into every cost display automatically — no other state to sync. - Also registers the
/deepseek-tiercommand to show which tier is active right now, and sets a footer status (peak ⚠️/off-peak) that only updates when the tier flips (disableable, see Configuration).
Official rate schedule (as of 2026)
Peak hours: 01:00–04:00 & 06:00–10:00 UTC (09:00–12:00 & 14:00–18:00 Beijing). Off-peak rates are exactly half of peak. DeepSeek does not charge for cache writes.
| Model | Tier | Input (cache miss) | Output | Cache hit (input) | Cache write |
|---|---|---|---|---|---|
| deepseek-v4-flash | peak | $0.44 /M | $1.32 /M | $0.014 /M | $0 |
| deepseek-v4-flash | off-peak | $0.22 /M | $0.66 /M | $0.007 /M | $0 |
| deepseek-v4-pro | peak | $1.32 /M | $3.96 /M | $0.044 /M | $0 |
| deepseek-v4-pro | off-peak | $0.66 /M | $1.98 /M | $0.022 /M | $0 |
| deepseek-v4-flash-vision-exp | peak | $0.44 /M | $1.32 /M | $0.014 /M | $0 |
| deepseek-v4-flash-vision-exp | off-peak | $0.22 /M | $0.66 /M | $0.007 /M | $0 |
Install
pi install npm:pi-deepseek-pricing-by-time
or from a local clone of this repo:
pi install ./extensions/deepseek-pricing-by-time
Usage
When a DeepSeek response completes, its cost is re-priced at the tier in effect for that message's timestamp:
message_endcorrects the stored per-message cost before it is summed into session totals, so the footer/statuslinecostsegment is accurate in real time./deepseek-tierreports the currently active tier and its rates (useful for deciding when to run a batch).
Configuration
The footer tier status is on by default. It can be disabled from project settings (when the project is trusted) or global settings, with project settings taking precedence:
{
"deepseekPricingByTime": false
}
or the object form:
{
"deepseekPricingByTime": {
"showTierStatus": false
}
}
Cost re-pricing itself is always on; only the footer status indicator is affected.
Optionally: keep models.json as the fallback
If you also override DeepSeek rates in ~/.pi/agent/models.json (e.g. with the
off-peak values, since most of the day is off-peak), keep them — they remain the
baseline for any message this extension does not touch (for example other frontends
that consume your config). This extension corrects the display on top of them.
Customizing
The rate table and peak windows live in the top of deepseek-pricing-by-time.ts
(PEAK_HOURS_UTC and RATES). Edit them there if DeepSeek changes the schedule or
prices, or to add other models. The peak windows are defined in UTC on purpose —
DeepSeek publishes them in UTC and your local timezone must not affect the tier.
Compatibility
- pi 0.84+ (uses the
message_endextension event andctx.uistatus API). - Tested with
deepseek-v4-flash,deepseek-v4-pro, anddeepseek-v4-flash-vision-expon the official DeepSeek API. - Cost correctness is display-side: like all pi cost accounting, it is an estimate based on reported usage tokens and published rates, not an invoice.
License
MIT