# Don't hardcode LLM prices: a nightly price-check job for your agent budget

> Source: <https://dev.to/tokenlean/dont-hardcode-llm-prices-a-nightly-price-check-job-for-your-agent-budget-14cb>
> Published: 2026-11-28 14:05:35+00:00

**Recommendation:** Store model prices in prices.json with a verified date and run a nightly cron check against official vendor pages that alerts on drift instead of auto-updating.
More in the playbook "Controlling LLM cost": <https://wpnews.pro/playbooks/llm-cost>

Most agent cost dashboards I see have a dict like `PRICES = {"model-x": 3.00}` pasted in months ago. Prices have moved a lot this month (cache cuts, search fees dropped, a scheduled doubling), and third-party trackers even disagree with each other on same-day swings. A stale constant silently wrecks your budget math.

Keep prices in a JSON file, and have a nightly job compare it against the official pricing pages. The job never edits prices itself: it only flags drift so a human confirms against the vendor page.

| Piece | What it does | 
|---|---|
| prices.json | Your single source of truth, with a verified date per model | 
| check.py | Fetches your vendor pricing pages and looks for the listed numbers | 
| cron | Runs nightly, writes an alert file or pings you | 

``` python
import json, sys, urllib.request, datetime

PRICES = json.load(open("prices.json"))
# each entry: {"url": "...pricing page...", "input": 3.00, "output": 15.00, "verified": "2026-11-28"}

def page(url):
    req = urllib.request.Request(url, headers={"User-Agent": "price-check/1.0"})
    return urllib.request.urlopen(req, timeout=20).read().decode("utf-8", "ignore")

drift = []
for model, p in PRICES.items():
    try:
        text = page(p["url"])
    except Exception as e:
        drift.append(f"{model}: fetch failed ({e})"); continue
    for key in ("input", "output"):
        if f"{p[key]:.2f}" not in text and str(p[key]) not in text:
            drift.append(f"{model}: {key} price {p[key]} not found on page")

if drift:
    open("DRIFT.txt", "w").write(datetime.date.today().isoformat() + "\n" + "\n".join(drift))
    sys.exit(1)
```

Cron line: `15 6 * * * cd /opt/pricecheck && python3 check.py || mail -s "LLM price drift" you@example.com < DRIFT.txt`

This is a tiny always-on job, and your laptop sleeps. A cheap VPS runs it, keeps the history, and can also host the model router that reads the same prices.json. [Get a Hostinger VPS here](https://go.nowto.link/hostinger?s=devto) if you want somewhere to put it.

| Rule | Reason | 
|---|---|
| Only trust official pricing pages | Aggregators hold back or conflict on single-day moves | 
| Alert, never auto-update | A page layout change can look like a price change | 
| Store a verified date | You can see how stale a number is | 
| Budget with the higher of old and new | Scheduled increases hit mid-month | 

Seed prices.json with the three models you actually call, run the script by hand once, then schedule it. [Read the full write-up on the TokenLean hub](https://tokenlean.wordpress.com/2026-11-28/llm-price-check-job/).

*Disclosure: some links in this article are affiliate links. If you buy through them, TokenLean may earn a commission at no extra cost to you.*
