DEV Community

Cover image for I Wrote a Script to Track My DeepSeek API Costs After the Weekend Pricing Change
Felix
Felix

Posted on

I Wrote a Script to Track My DeepSeek API Costs After the Weekend Pricing Change

The Bill That Made Me Curious

I don't normally check my API dashboard more than once a week. But last Sunday I did, out of boredom, and the number was lower than I expected for how much I'd been running.

Turns out DeepSeek quietly changed its peak/off-peak billing structure. According to their pricing docs, peak hours are now strictly Monday–Friday, 01:00–04:00 and 06:00–10:00 UTC. Everything else — including all of Saturday and Sunday — bills at off-peak rates, which run at roughly half of peak pricing for both input and output tokens.

I run most of my testing on weekends (day job during the week), so in theory this should matter a lot for me. But "in theory" isn't good enough when I'm the one paying the invoice. I wanted actual numbers from my actual usage, not a guess.

So I wrote a small script.

What the Script Does

Nothing fancy — it takes a log of my API calls (timestamp + input/output token counts) and calculates what I actually paid under the new peak/off-peak rules, split by weekday vs weekend.

import csv
from datetime import datetime, timezone

# Pricing per 1M tokens (cache miss), off-peak / peak
PRICING = {
    "deepseek-v4-flash": {
        "input_offpeak": 0.22, "input_peak": 0.44,
        "output_offpeak": 0.66, "output_peak": 1.32,
    },
    "deepseek-v4-pro": {
        "input_offpeak": 0.66, "input_peak": 1.32,
        "output_offpeak": 1.98, "output_peak": 3.96,
    },
}

def is_peak(dt_utc):
    # Peak: Mon-Fri, 01:00-04:00 and 06:00-10:00 UTC
    if dt_utc.weekday() >= 5:  # Sat=5, Sun=6
        return False
    hour = dt_utc.hour
    return (1 <= hour < 4) or (6 <= hour < 10)

def calc_cost(model, input_tokens, output_tokens, dt_utc):
    rates = PRICING[model]
    peak = is_peak(dt_utc)
    in_rate = rates["input_peak"] if peak else rates["input_offpeak"]
    out_rate = rates["output_peak"] if peak else rates["output_offpeak"]
    cost = (input_tokens / 1_000_000) * in_rate + (output_tokens / 1_000_000) * out_rate
    return cost, peak

def analyze_log(csv_path):
    weekday_cost, weekend_cost = 0.0, 0.0
    weekday_calls, weekend_calls = 0, 0

    with open(csv_path) as f:
        reader = csv.DictReader(f)
        for row in reader:
            dt = datetime.fromisoformat(row["timestamp"]).astimezone(timezone.utc)
            cost, peak = calc_cost(
                row["model"],
                int(row["input_tokens"]),
                int(row["output_tokens"]),
                dt,
            )
            if dt.weekday() >= 5:
                weekend_cost += cost
                weekend_calls += 1
            else:
                weekday_cost += cost
                weekday_calls += 1

    print(f"Weekday: {weekday_calls} calls, ${weekday_cost:.4f}")
    print(f"Weekend: {weekend_calls} calls, ${weekend_cost:.4f}")

if __name__ == "__main__":
    analyze_log("api_usage_log.csv")
Enter fullscreen mode Exit fullscreen mode

Expected CSV format:

timestamp,model,input_tokens,output_tokens
2026-08-22T14:32:00+00:00,deepseek-v4-flash,1200,340
2026-08-23T09:15:00+00:00,deepseek-v4-flash,980,410
Enter fullscreen mode Exit fullscreen mode

You'll need to export your own usage log — DeepSeek's dashboard lets you download call history, or you can log it yourself at request time if you're not already.

What I Actually Found

Running this against about six weeks of my own logs: my weekend calls were consistently cheaper per-token than my weekday calls even before this change (because some of my weekend hours already fell outside the old off-peak window by luck). After the update, the gap widened — my weekend cost-per-call dropped further since Saturday and Sunday are now unconditionally off-peak, no matter the hour.

For someone running a handful of batch jobs on weekends, that's a real, if modest, saving. Your mileage depends entirely on when you actually run your workload — if most of your usage happens on weekday afternoons, this change does nothing for you.

The Question I Couldn't Answer With This Script

Once I had this data, the obvious next question was: how would the same workload cost on a different model? The script above only works because I already know DeepSeek's pricing structure. Answering the same question for Qwen or GLM would mean writing a whole new pricing table and, more annoyingly, a whole new API integration to actually generate comparable token logs.

That's the part I didn't script around — I switched my project to call models through RouteAI, an OpenAI-compatible API gateway, mainly so I could point the same request format at different models without rebuilding my client code each time. It didn't change the cost-tracking logic above, but it meant I could actually go collect that data for other models instead of just wondering about it. Worth noting this only saved me integration time — the actual per-token pricing is still whatever each model provider sets.

If You Want to Run This Yourself
Export or log your own usage with timestamps in UTC (not local time — this bit me on my first run)
Add pricing tiers for whichever models you're using; I only included flash and pro here
If you're on a different provider, check whether they have time-based pricing at all before assuming this script applies

TL;DR: DeepSeek's new pricing makes weekends fully off-peak (previously only certain hours were). I wrote a Python script to calculate actual cost split between weekday/weekend usage from a call log — script included above, MIT-license it however you like.

Worth exploring if this is relevant to your stack: www.fastrouteai.com

Top comments (0)