{"slug": "don-t-hardcode-llm-prices-a-nightly-price-check-job-for-your-agent-budget", "title": "Don't hardcode LLM prices: a nightly price-check job for your agent budget", "summary": "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.", "body_md": "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.\n\nKeep 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.\n\n| Piece | What it does | \n|---|---|\n| prices.json | Your single source of truth, with a verified date per model | \n| check.py | Fetches your vendor pricing pages and looks for the listed numbers | \n| cron | Runs nightly, writes an alert file or pings you | \n\n``` python\nimport json, sys, urllib.request, datetime\n\nPRICES = json.load(open(\"prices.json\"))\n# each entry: {\"url\": \"...pricing page...\", \"input\": 3.00, \"output\": 15.00, \"verified\": \"2026-11-28\"}\n\ndef page(url):\n    req = urllib.request.Request(url, headers={\"User-Agent\": \"price-check/1.0\"})\n    return urllib.request.urlopen(req, timeout=20).read().decode(\"utf-8\", \"ignore\")\n\ndrift = []\nfor model, p in PRICES.items():\n    try:\n        text = page(p[\"url\"])\n    except Exception as e:\n        drift.append(f\"{model}: fetch failed ({e})\"); continue\n    for key in (\"input\", \"output\"):\n        if f\"{p[key]:.2f}\" not in text and str(p[key]) not in text:\n            drift.append(f\"{model}: {key} price {p[key]} not found on page\")\n\nif drift:\n    open(\"DRIFT.txt\", \"w\").write(datetime.date.today().isoformat() + \"\\n\" + \"\\n\".join(drift))\n    sys.exit(1)\n```\n\nCron line: `15 6 * * * cd /opt/pricecheck && python3 check.py || mail -s \"LLM price drift\" you@example.com < DRIFT.txt`\n\nThis 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.\n\n| Rule | Reason | \n|---|---|\n| Only trust official pricing pages | Aggregators hold back or conflict on single-day moves | \n| Alert, never auto-update | A page layout change can look like a price change | \n| Store a verified date | You can see how stale a number is | \n| Budget with the higher of old and new | Scheduled increases hit mid-month | \n\nSeed 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/).\n\n*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.*", "url": "https://wpnews.pro/news/don-t-hardcode-llm-prices-a-nightly-price-check-job-for-your-agent-budget", "canonical_source": "https://dev.to/tokenlean/dont-hardcode-llm-prices-a-nightly-price-check-job-for-your-agent-budget-14cb", "published_at": "2026-11-28 14:05:35+00:00", "updated_at": "2026-11-28 14:14:16.113794+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools"], "entities": ["TokenLean", "Hostinger"], "also_reported_by": [], "takeaway": "Keep LLM prices in a versioned JSON file with a verified date and run a nightly script that only flags drift against official vendor pages, since a stale hardcoded price silently breaks agent budget math.", "recommendation": {"advice": "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.", "playbook": "llm-cost", "playbook_url": "https://wpnews.pro/playbooks/llm-cost"}, "alternates": {"html": "https://wpnews.pro/news/don-t-hardcode-llm-prices-a-nightly-price-check-job-for-your-agent-budget", "markdown": "https://wpnews.pro/news/don-t-hardcode-llm-prices-a-nightly-price-check-job-for-your-agent-budget.md", "text": "https://wpnews.pro/news/don-t-hardcode-llm-prices-a-nightly-price-check-job-for-your-agent-budget.txt", "jsonld": "https://wpnews.pro/news/don-t-hardcode-llm-prices-a-nightly-price-check-job-for-your-agent-budget.jsonld"}}