OpenAI Stats
Embeddable SVG activity cards for GitHub READMEs, combining OpenAI API usage with locally exported subscription activity on Cloudflare Workers.
OpenAI Stats turns token usage into an activity card that can be embedded in a GitHub README. It brings API usage and locally exported subscription activity into a familiar calendar grid, served as a single SVG image.
What It Does
Choose API, subscription, or combined activity, then set the history length and light or dark theme. The card shows daily activity and summary statistics, with dates and counts available in tooltips and accessible text. The live demo uses subscription activity; the repository's preview images use synthetic data.
Tech Stack
The service is written in TypeScript and runs on Cloudflare Workers. It generates SVG directly and uses Cloudflare's Cache API for temporary storage. Subscription snapshots are bundled at deployment, keeping the app small enough to run without a database or frontend application.
Two Sources, Different Refresh Cycles
API activity is fetched in bounded date windows, with pagination and limited concurrency. Daily aggregates are cached separately from rendered cards, allowing different themes to reuse the same fetched data.
Subscription activity comes from a local export through the Codex CLI. Only usage statistics and an export timestamp are bundled into the Worker. These cards refresh when a new snapshot is exported and deployed, and distinguish unreported days from recorded zero usage.
Engineering Details
Theme variants expire with their underlying data, preventing a newly rendered card from extending the life of stale results. The repository includes tests for aggregation, UTC date boundaries, SVG escaping, pagination, failures, and cache behavior, plus a runtime smoke test with synthetic responses.