Michael Liyang: record every AI call in D1 and downgrade before the budget runs out
@Michael_liyang argues that on a free tier the danger is not one expensive call but not knowing which call is expensive: write each call's usage to D1 by user and model, have a daily Cron check budgets and downgrade first, and look at which user is burning quota rather than only the total.
- Products
- D1Workers AIWorkers
- Source
- Author experience𝕏 post
- Author
- 风易 | AI 工具链
Key points
- The chain he describes: call → record → aggregate → downgrade when over budget; without a ledger, you can only guess when the bill arrives.
- In replies he suggests two downgrade levels (switch to a second-tier model at 80% of budget; return 429 and stop high-cost routes at 100%, resampling after the UTC midnight reset), recording user_id/model/prompt_tokens/completion_tokens/status per call, and a daily budget keyed by budget_day/user_id/model/spent_neurons.
Original sources
Published
Original post
Read on 𝕏@Michael_liyang argues that on a free tier the danger is not one expensive call but not knowing which call is expensive: write each call's usage to D1 by user and model, have a daily Cron check budgets and downgrade first, and look at which user is burning quota rather than only the total.
风易 | AI 工具链
@Michael_liyang · Original 𝕏 post
先说结论:免费档最怕的不是单次贵,是不知道哪次贵。 每次调用就记一笔账:prompt、completion 多少,哪个模型、谁在用。 做法:1 调用完把用量写 D1,按用户+模型汇总;2 每天 Cron 扫一遍,超预算先降级;3 别只看总额,看哪个用户在烧。 链路:调用→记账→汇总→超预算降级。 没账本,账单来了只能猜。
Reply: two-level downgrade — second-tier model at 80% of budget, 429 and stop high-cost routes at 100%, resample after the UTC midnight reset.
Read on 𝕏风易 | AI 工具链
@Michael_liyang · Original 𝕏 post
@web3xiaoZ 建议双层降级:80% 预算切次旗舰,100% 返回 429 并停高成本路由;UTC 零点重置后重新采样。
Reply: write user_id/model/prompt_tokens/completion_tokens/status for every call; totals alone cannot show which user is burning quota.
Read on 𝕏风易 | AI 工具链
@Michael_liyang · Original 𝕏 post
@TrainCodeMan 补一个字段:每次调用同时写 `user_id / model / prompt_tokens / completion_tokens / status`;只记总额,后面无法定位哪个用户在烧。
Reply: turn the real-time ledger into a daily budget (budget_day/user_id/model/spent_neurons) and downgrade at the budget line instead of waiting for the bill.
Read on 𝕏风易 | AI 工具链
@Michael_liyang · Original 𝕏 post
@CryptotoMoses 实时记账直接做成日预算:`budget_day / user_id / model / spent_neurons`,到预算线先降级;等账单下来才看就已经晚了。
More to read
cloudflare-cost-notify: a Worker cron that posts daily billable usage and free-tier counts to Discord
yutamoty/cloudflare-cost-notify is an unlicensed GitHub repository, pushed on 16 November 2026. A Cloudflare Worker cron at 00:00 UTC (described as 09:00 JST) reads the Billable Usage API and GraphQL Analytics API and posts yesterday’s cost, the day-over-day change, month-to-date spend, and Workers request / R2 storage / R2 Class A and B counts to a Discord webhook. A default $0.00 alert threshold turns the message red. Because the repository has no license, this entry is a summary only and the README is not archived in sources.json.
Kun Save Point (@Savepoint_kk): a D1 bug rewrote unchanged data into a $2,739.12 bill; $2,141 goodwill credit granted.
Kun Save Point (@Savepoint_kk), an indie developer who says he recently lost his job, says a bug repeatedly rewrote unchanged data while inefficient queries amplified reads, producing a $2,739.12 Cloudflare bill already paid via PayPal (D1 rows written $2,641.00, rows read $64.06, other services $34.06); he says his bills were usually under $10 a month. Cloudflare granted a $2,141 goodwill account credit under case #02391058. He asks for it to be converted into a refund to the original PayPal payment, or at least for relief on the $2,641 write charges, and later writes that the initial request was declined and has been reopened for additional review. On October 25 he adds that he missed the only alert email Cloudflare sent, whose amount was not particularly high, and received no further warning before the large card charge; on October 26 he writes that the refund request to the original payment method is still under further review. On November 10 he posts a timeline saying that after following up on November 10–11, support again stated the $2,141 could only remain as account credit and the remaining $598.12 was still undecided while the ticket was being closed.
Workers Free: SQLite Durable Object row-write quota can still block after the 00:00 UTC reset
Two Workers Free users with SQLite-backed Durable Objects report that after exceeding the 100,000 daily row-write allowance, storage still threw “Exceeded allowed rows written in Durable Objects free tier” after the documented 00:00 UTC reset, even though GraphQL analytics already showed 0 rows written for the new UTC day. @vendasecoplast1 saw 114,211 rows written and 399,088 rows read on 2026-11-16 UTC, then a failure at 2026-11-17 00:17:32 UTC during CREATE TABLE IF NOT EXISTS in the constructor. @dimoncheck2020 saw 103,558 rows written on 2026-11-18 UTC and 24 failed Durable Object invocations with 0 rows written between 00:00:00 and 00:35:27 UTC on 2026-11-19, with the same constructor exception at 00:35:21 UTC. No Cloudflare staff reply as of 2026-11-19.