Documentation
¶
Overview ¶
Command wg-costimport copies AI Gateway spend into usage_records.
Cloudflare is the only place spend exists today, and it is the wrong place to keep it: the log rotates on DELETE_OLDEST, so the evidence for any cost claim disappears on Cloudflare's schedule rather than ours, and a log entry carries no project, so "what did this project cost" cannot be asked at all. This program answers both by making the record durable and joinable.
One pass per invocation on a systemd timer, for the reasons wg-monitor is built the same way: the timer is externally visible, a crash needs no supervision logic here, and a missed run is something the operating system records.
Re-running is always safe. Every entry carries the gateway's own id and the write is ON CONFLICT DO NOTHING, so an overlapping window costs a few wasted round trips and nothing else. The import therefore deliberately re-reads a window behind the watermark instead of resuming exactly at it: an entry that arrives out of order would otherwise be skipped forever.