{"slug": "show-hn-fiscallm-open-source-per-user-ai-cost-for-subscription-apps", "title": "Show HN: FiscaLLM:open-source per-user AI cost for subscription apps", "summary": "FiscaLLM, an MIT-licensed open-source tool published to npm and PyPI as the `fiscallm` package, tracks per-user AI spend for subscription apps by reading only the model name and token counts from each AI response and joining that cost against revenue from RevenueCat or Stripe webhooks on the user ID. The tool prices cost on arrival — exact `costUsd` when supplied, otherwise per-token rates for input, output, cache read and cache write or per-unit rates for images, audio and video — and flags unknown models as unpriced rather than counting them as zero. It adds per-user budgets with email, Slack or signed-webhook alerts and optional spending caps via `meter.check(userId)`, which fails open if FiscaLLM is slow or down.", "body_md": "**See the AI cost of every single user.** FiscaLLM adds up what each user costs you in AI and sets it next to what they pay you, so you can see who is profitable and who is losing you money.\n\n**Open source (MIT) and free.** Use the hosted service at [fiscallm.com](https://fiscallm.com) (free under fair use, best effort), or [run your own](https://github.com/magna56/fiscallm/blob/main/SELF-HOSTING.md).\n\n[Live demo (no sign-up)](https://fiscallm.com/demo) · [Docs](https://fiscallm.com/docs) · [How it works](https://fiscallm.com/how-it-works) · [What it covers](https://fiscallm.com/coverage) · [Accuracy](https://github.com/magna56/fiscallm/blob/main/ACCURACY.md) · [Roadmap](https://github.com/magna56/fiscallm/blob/main/ROADMAP.md) ([board](https://github.com/users/magna56/projects/1)) · [Changelog](https://github.com/magna56/fiscallm/blob/main/CHANGELOG.md) · [Self-hosting](https://github.com/magna56/fiscallm/blob/main/SELF-HOSTING.md) · [Contributing](https://github.com/magna56/fiscallm/blob/main/CONTRIBUTING.md)\n\n*Sample data from the demo, not a real customer.*\n\n1. \n**Create an app** at[fiscallm.com](https://fiscallm.com) (or your own copy) and copy the ingest key.\n2. \n**Add one line after each AI call** (it reads only the model name and token counts, never prompts or answers):\n\n``` js\nimport { createMeter } from \"fiscallm\"; // npm install fiscallm   (Python: pip install fiscallm)\nconst meter = createMeter({ apiKey: process.env.FISCALLM_KEY, waitUntil });\n\nconst res = await openai.chat.completions.create({ model, messages });\nmeter.trackOpenAI(res, { userId, feature: \"chat\" });\n```\n\n3. \n**Connect revenue** : paste a RevenueCat or Stripe webhook URL, or send payments yourself with the revenue API.\n\nNo AI key handy? `FISCALLM_KEY=fsk_... node examples/send-sample-data.mjs` fills a test app with sample users so you can see it working.\n\nAI apps charge a flat price but pay a variable cost. One user costs $0.20 a month in AI, another costs $25. Your AI provider's bill shows tokens, your subscription tool shows payments, and neither shows the user.\n\n``` js\nimport { createMeter } from \"fiscallm\";\n\nconst meter = createMeter({ apiKey: process.env.FISCALLM_KEY, waitUntil });\n\nconst res = await openai.chat.completions.create({ model, messages });\nmeter.trackOpenAI(res, { userId, feature: \"chat\" });\npython\nfrom fiscallm import Meter\n\nmeter = Meter(api_key=os.environ[\"FISCALLM_KEY\"])\nres = client.chat.completions.create(model=model, messages=messages)\nmeter.track_openai(res, user_id=user_id, feature=\"chat\")\n```\n\n- The SDK reads **only the model name and token counts** from the response. Never prompts or answers.\n- Events are batched and sent in the background. Tracking never throws and never blocks your response.\n- Each event has a client-generated UUID, so retries cannot double count.\n- Revenue comes from a RevenueCat webhook, or from your own code with `trackRevenue` /`track_revenue` .\n- Both are joined on the user ID. RevenueCat aliases are resolved, so anonymous and logged-in users merge.\n- **Budgets and alerts** : email, Slack or signed webhooks when a user goes over budget, when a paying user loses money, or when one user burns a huge number of tokens in 5 minutes (a runaway loop).\n- **Spending caps** : mark a per-user budget as Block and call`meter.check(userId)` before an AI call (TypeScript, Python). It says no once the user reaches the amount, and**fails open** if FiscaLLM is slow or down.\n\nCost is priced on arrival: exact `costUsd` if given, otherwise per-token (input, output, cache read and cache write priced separately) or per-unit (images, audio, video) from a price table. Unknown models are flagged as unpriced, never counted as zero.\n\nNet revenue is `price × (1 − tax − store commission)`.\n\n| Path | What it is | \n|---|---|\n| `apps/web` | Next.js site and dashboard | \n| `apps/api` | Hono API: ingest, RevenueCat webhook, revenue API, cron jobs | \n| `packages/shared` | Drizzle schema, pricing, metrics, alerts | \n| `packages/sdk` | TypeScript SDK ( `fiscallm` on npm) | \n| `packages/sdk-python` | Python SDK ( `fiscallm` on PyPI) | \n\nStack: TypeScript, Next.js, Hono, Postgres (Supabase) with Drizzle, hosted on Vercel.\n\n- It needs a backend between your app and the AI provider. Apps that call a provider straight from the phone are not covered yet.\n- Revenue comes from RevenueCat, Stripe (beta, USD only) or the revenue API. Direct App Store and Google Play connections are not built yet.\n\n- No AI key needed: `FISCALLM_KEY=fsk_... node examples/send-sample-data.mjs` fills the dashboard with sample users (one heavy user who loses money).\n- Copy-paste starting points for [Next.js](https://github.com/magna56/fiscallm/blob/main/examples/nextjs) and[FastAPI](https://github.com/magna56/fiscallm/blob/main/examples/fastapi) , see[examples](https://github.com/magna56/fiscallm/blob/main/examples) .\n- Run your own copy: [SELF-HOSTING.md](https://github.com/magna56/fiscallm/blob/main/SELF-HOSTING.md) ).\n\n```\npnpm install\npnpm dev:web   # http://localhost:3000\npnpm dev:api   # http://localhost:8787/api/health\npnpm test\n```\n\nCopy `.env.example` to `apps/web/.env.local` and `packages/shared/.env` and fill in the values.\n\n```\npnpm db:generate\npnpm db:migrate\n```\n\nIssues and pull requests are welcome. Read [CONTRIBUTING.md](https://github.com/magna56/fiscallm/blob/main/CONTRIBUTING.md) first (it includes a short contributor agreement). The plan, including what we only build if there is demand, is in [ROADMAP.md](https://github.com/magna56/fiscallm/blob/main/ROADMAP.md), with a [public board](https://github.com/users/magna56/projects/1). Vote with a 👍 on [roadmap issues](https://github.com/magna56/fiscallm/issues?q=is%3Aissue+is%3Aopen+label%3Aroadmap) or share ideas in [Discussions](https://github.com/magna56/fiscallm/discussions/categories/ideas).\n\n**Where help is most wanted:** prices for more models and providers (data only, no code knowledge needed), connectors for other billing systems (Adapty, Superwall), examples for AI frameworks, and a comparison of computed costs with a real provider invoice. See the [good first issues](https://github.com/magna56/fiscallm/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22).\n\nBuilt and maintained by [Mayur](https://www.linkedin.com/in/mayur-agnani/) as an independent, open-source side project. Questions, bugs and ideas: [open an issue](https://github.com/magna56/fiscallm/issues) or email [theaicommit@gmail.com](mailto:theaicommit@gmail.com).\n\nThank you to everyone who helps. [Contribute](https://github.com/magna56/fiscallm/blob/main/CONTRIBUTING.md): a good place to start is an issue labelled `good first issue`.\n\nMIT. See [LICENSE](https://github.com/magna56/fiscallm/blob/main/LICENSE).", "url": "https://wpnews.pro/news/show-hn-fiscallm-open-source-per-user-ai-cost-for-subscription-apps", "canonical_source": "https://github.com/magna56/fiscallm", "published_at": "2026-10-22 13:27:23+00:00", "updated_at": "2026-10-22 13:41:38.804325+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-products", "ai-infrastructure"], "entities": ["FiscaLLM", "RevenueCat", "Stripe", "OpenAI", "npm", "PyPI", "GitHub"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/show-hn-fiscallm-open-source-per-user-ai-cost-for-subscription-apps", "markdown": "https://wpnews.pro/news/show-hn-fiscallm-open-source-per-user-ai-cost-for-subscription-apps.md", "text": "https://wpnews.pro/news/show-hn-fiscallm-open-source-per-user-ai-cost-for-subscription-apps.txt", "jsonld": "https://wpnews.pro/news/show-hn-fiscallm-open-source-per-user-ai-cost-for-subscription-apps.jsonld"}}