cd /news/ai-agents/don-t-hardcode-llm-prices-a-nightly-… · home › topics › ai-agents › article
[ARTICLE · art-177765] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

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

A developer published a small Python job that keeps LLM pricing in a local prices.json file and checks it nightly against official vendor pricing pages, flagging any drift to a human rather than auto-updating. The script fetches each model's pricing page, searches for the stored input and output numbers, and on a mismatch writes a DRIFT.txt file and exits non-zero so cron can email an alert. The write-up recommends trusting only official pages, storing a verified date per model, and budgeting with the higher of old and new prices.

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 playbook: Controlling LLM cost
by read2 min views2 publishedNov 28, 2026

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
import json, sys, urllib.request, datetime

PRICES = json.load(open("prices.json"))

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 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.

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.

── more in #ai-agents 4 stories · sorted by recency
── more on @tokenlean 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/don-t-hardcode-llm-p…] indexed:0 read:2min 2026-11-28 · —