Cloudflare Medivh: a self-hosted near-real-time bill estimator
An open-source, self-hosted monitor that adds today’s estimated usage cost to Cloudflare’s daily-updated billable usage, sends summaries, and calls a webhook when the current cycle crosses a budget.
- Products
- WorkersWorkers LogsWorkers BuildsContainersDurable ObjectsR2QueuesD1Workers KV
- Source
- Community resourceGitHub repository
- Author
- NPC_Jyy (@jinyang1994)
Key points
- The README says Cloudflare’s Billable Usage API updates daily and not exactly at 00:00 UTC, so intraday spikes are hard to notice. Medivh estimates the current cycle as the official cumulative cost through yesterday plus today’s estimated increment, retries the official sync after 00:00 UTC, and rechecks the last three days for late or revised charges.
- It collects every 10 minutes, can push summaries to a Feishu bot, and can call a budget webhook when the official-plus-estimate total strictly exceeds a threshold set in integer cents. The webhook fires once per billing cycle, only for USD cycles, and carries an Idempotency-Key.
- Stated limits: it only monitors, reconciles and notifies; it does not stop Cloudflare services and is not a hard cap. The author explains that stopping some services, such as Durable Objects, must be built into business logic, so only a webhook is exposed. Unit prices live in a local price table that does not follow official price changes, analytics can lag or be sampled, and Workers Logs history is limited to seven days.
- The token needs Account Billing Read and Account Analytics Read, plus Workers Observability Write because the log query API currently requires it. The dashboard has no built-in login, and the README says the project was mainly written by vibe coding.
Original sources
Original source · Last updated
Open original sourceThe author says he is preparing to open-source the bill monitoring and auto-disable service he uses.
Read on 𝕏NPC_Jyy
@jinyang1994 · Original 𝕏 post
我已经准备开源我用的监控账单自动停用服务了
The author writes that the bill available through the API only covers up to yesterday, so a real-time bill has to be calculated yourself.
Read on 𝕏NPC_Jyy
@jinyang1994 · Original 𝕏 post
赞同,主要恶心的在于API获取的账单只能是昨天的。 如果你想拿到实时账单,需要自己手动算... pic.twitter.com/tw7mmeWQ6T
Open-source announcement: the service calculates the bill in real time, sends it periodically, and calls a webhook when over the limit for emergency shutdown or phone alerts; the author hopes it helps before Cloudflare ships hard caps.
Read on 𝕏NPC_Jyy
@jinyang1994 · Original 𝕏 post
开源了一个Cloudflare账单监控服务。 可以实时计算账单,定期发送实时账单,超出限额调用webhook(用来实现紧急停用服务或电话通知)。 希望在Cloudflare发布账单硬顶功能前能帮助到大家。 欢迎大家试用,反馈不同场景下的问题,让系统健壮起来。 求扩散 @imwsl90https://t.co/27j21d0L38 https://t.co/qwS3k33VxS
Another author, M. (@wlzh), introduces Medivh as collecting every 10 minutes with Feishu summaries and a threshold webhook, and stresses that it only monitors and alerts; it does not stop services automatically and is not a hard cap.
Read on 𝕏M.
@wlzh · Original 𝕏 post
前几天一位老哥,Codex 的代码 bug 让他的项目在 Cloudflare 上一晚上刷掉一万多刀。 这事儿把另一位老哥吓得夜不能寐:自己的项目全搭在 Cloudflare 上,代码还都是 AI 写的,万一哪天睡觉的时候被刷破产了呢? 于是有人直接开源了一个 Cloudflare 账单监控服务,叫…
More to read
Why hard spending caps take time: Ashley Peacock on billing latency
Ashley Peacock (@ashleypeacock), who works on Durable Objects at Cloudflare, explains from experience why near-real-time spending caps are hard to build, says hard billing caps are coming soon, and suggests budget alerts plus issue alerts in the meantime.
Steven Menke: an Agents SDK bug and a reported $1,700 Durable Objects invoice.
Steven Menke (@Galorious_) reports that runaway Durable Objects caused by an Agents SDK bug produced a $1,700 invoice in three days, citing one trillion SQLite reads (a later post says writes). He says his support ticket, even after a maintainer escalated it, received no reply for months.
Layered defenses after a Durable Object alarm loop
星星之火可以燎原 (@fireandstart) reads a public Durable Object alarm-loop recap and argues for layered defenses rather than relying on being more careful next time.