Skip to Content
v1.41.2 · shipped More settings on the script tag · Script tag typos no longer slip through Read the changelog →

Cost importer

The break-even card starts from what Mushi Mushi can estimate alone. The cost importer replaces those estimates with measured figures. It is a script, scripts/cost-import.mjs in the Mushi Mushi repository. It runs where your credentials already are (your laptop or your CI) and posts only the results.

Mushi Mushi never receives your AWS, GitHub, Sentry or Supabase credentials. The importer reads them from your environment and sends Mushi Mushi lines like “Supabase project, $12.40 a month, this formula, measured”.

What it reads

SourceNeedsWhat it sends
SupabaseSUPABASE_ACCESS_TOKENEach organization’s plan and each project’s compute add-on: the plan once per organization, plus compute above the included credit. A project several apps share is split by the bytes each app’s tables and storage buckets take (from the prefixes and buckets in your config, or the table prefixes set on the break-even card). It is never divided by the number of apps: with nothing to split by, it posts no line and says so.
GitHub Actionsgh signed in as the billing accountYour net Actions cost per repository for 30 days, from /users/<user>/settings/billing/usage, as a bill per app (it shows on the Spend tab too).
SentrySENTRY_AUTH_TOKEN (org:read)Accepted error events per Sentry project for 30 days. The plan price is split by each app’s share.
AWSThe AWS CLI with a read-only profile (ce:GetCostAndUsage, cloudwatch:GetMetricStatistics)Cost Explorer by your cost-allocation tag (default project) as a bill per app. Until the tag has data: S3 split by bucket size, and the other services in one line not yet split by app.
App usageSUPABASE_ACCESS_TOKEN, a read-only SQL query in your configThe AI cost per active user (median and p90 over 30 days), priced from each provider’s list price. This is the variable cost per payer.
FixedYour configPlans with no usage API: a crawler plan, domains, a design tool.

Every line carries its formula, its inputs, its source (measured or list price), its confidence, the date, and how a shared cost was split.

Run it

  1. Open Portfolio → Break-even → Run the cost importer and choose Create an importer key. It is an account key with write access, shown once, and its owner must be a team owner or admin. Revoke it under MCP → Setup → Account keys. The panel also shows the commands below with your team id filled in.

  2. Clone the repository (git clone --depth 1 https://github.com/kensaurus/mushi-mushi; the script needs Node 20 or later and no install). Copy scripts/cost-import.example.json to a private place outside the repository and fill in your mapping: which app uses which tables, buckets, repositories, Sentry projects and AWS tag values.

  3. The GitHub source reads Actions billing with gh api, so your gh login needs the user scope (gh auth refresh -h github.com -s user). Without it the GitHub lines are skipped and the run says so.

  4. Dry-run it and read the result:

    MUSHI_API_KEY=mushi_… node scripts/cost-import.mjs \ --org <your team id> --config ~/private/cost-import.json \ --dry-run --out ~/private/cost-lines.json
  5. Run it without --dry-run to post. Re-running replaces the lines it posted before. A source that fails keeps its older lines and says why. Bills replace the days they cover.

--only supabase,github runs some sources. Under CI (CI=true) it prints counts, never amounts.

Your config

{ "github": { "user": "your-billing-user", "repos": { "repo-name": "app-slug" } }, "sentry": { "org": "your-org", "planUsd": 26, "projects": { "sentry-project": "app-slug" } }, "supabase": { "apps": { "app-slug": { "ref": "abcdefghijklmnopqrst", "tablePrefixes": ["app_"], "buckets": ["app-media"] } } }, "aws": { "tagKey": "project", "region": "ap-northeast-1", "buckets": { "app-media-bucket": "app-slug" } }, "appUsage": [ { "app": "app-slug", "supabaseRef": "abcdefghijklmnopqrst", "sql": "select user_id, model, sum(input_tokens) as input_tokens, sum(output_tokens) as output_tokens, count(*) as calls from app_ai_usage where created_at > now() - interval '30 days' group by user_id, model" } ], "fixed": [ { "component": "crawler", "vendor": "crawler", "label": "Crawler plan", "monthlyUsd": 16, "formula": "Hobby plan, list price" } ] }

Apps are named by their slug in Mushi Mushi. Repositories, Supabase projects and Sentry projects already set on an app (Settings → Integrations) are used without a mapping; the config only adds what Mushi Mushi cannot know. The usage query runs read-only and must return user_id, model, input_tokens and output_tokens (and optionally calls). A model with no list price in scripts/lib/model-prices.mjs is counted as $0 and the line says how many calls that was.

Keep it private

The config, the dry-run output and your figures belong to you. Keep them out of any repository. Mushi Mushi stores the posted lines in your team’s data, which only your team’s members can read.

Last updated on