NEWCost-aware experiments for self-hosted Flagsmith

Your A/B test winner might be losing you money.

Flagsmith tells you which variant converts. FlagLedger tells you which one pays for itself: net margin per flag variant and per user cohort, plus a fix you approve in one click.

Start with your Flagsmith login $docker compose up -d
MIT licensed No new SDK Human approves every change
search_bar_modeexample · one week
What the experiment says
+77%upgrades on ai_summary 98% chance to win
What the ledger says
Extra upgrade revenue+$886
Extra LLM + compute−$1,123
$0.014 per AI search · 35× the SQL search
Net margin / week−$237
Fix ready · +$464/wk
costuser_0412 · ai_summary$0.0140$flag_exposureuser_1180controlupgradeuser_0733 · free→pro+$20.00costuser_1544 · ai_summary$0.0162revenueuser_0081 · renewal+$20.00costuser_0968 · control$0.0004$flag_exposureuser_1902ai_summarycostuser_0207 · ai_summary$0.0131costuser_0412 · ai_summary$0.0140$flag_exposureuser_1180controlupgradeuser_0733 · free→pro+$20.00costuser_1544 · ai_summary$0.0162revenueuser_0081 · renewal+$20.00costuser_0968 · control$0.0004$flag_exposureuser_1902ai_summarycostuser_0207 · ai_summary$0.0131
The blind spot

Experiments measure clicks. The bill arrives three weeks later.

Every new AI feature ships behind a flag. Flagsmith knows who saw which variant and whether they converted. Your LLM and cloud costs live somewhere else, as one unlabelled number on an invoice.

Cost and conversions never meet

Nobody can open a flag and see what it burns per hour, or whether its winning variant earns more than it costs.

The winner can be a loss

Free users search the most and pay nothing. A variant that lifts upgrades by 77% can still lose money on their token bill.

A kill switch throws away the gains

Turning the feature off for everyone loses the Pro users who renew because of it. The fix belongs to one cohort, not the whole flag.

Example · NoteFlow search

Split the result by who pays.

FlagLedger breaks every variant down by the traits you already send to Flagsmith. Here the AI search pays for itself with Pro users and leaks money on the free plan.

2,000 identities · 80% free · 20% pro
control $0.0004/search · ai_summary $0.014/search

plan = pro · ai_summary+$252/wk
plan = free · ai_summary−$489/wk
Estimate vs actual

Everyone estimates. FlagLedger checks the estimate against what users actually did.

Every launch has a cost spreadsheet: price per call × calls per user. The price is easy to look up. The usage is a guess, and the better the feature works, the more people use it, so the better the A/B result, the more wrong the estimate.

The launch spreadsheet

  • Written once, three weeks before launch
  • One average user
  • Guessed calls per user × list price
  • Lives in a doc nobody opens on ship day

FlagLedger

  • Updates with every session Flagsmith records
  • Split by plan, the cohort that pays or doesn’t
  • Measured usage, priced from real Claude token bills
  • Next to Flagsmith’s verdict, with a fix to approve

Price check: the cost per AI search, measured

12 real searches through Claude · priced from the token usage it reports
Spreadsheet said$0.0140a guess
Measured · Claude Opus 5.5$0.0127~1,540 tokens in · ~330 out
Same searches · Claude Haiku 5.5$0.0003635× cheaper · the next variant to test

The price was close. The loss came from usage: free users run about 45 AI searches a week and pay nothing. The spreadsheet’s average hid it; the per-cohort ledger shows it on the screen where you decide to ship.

How it works

Flagsmith picks the winner. FlagLedger checks the bill. You approve the fix.

Step 1

Send cost as a Flagsmith event

One extra call after each paid request, through the same SDK and pipeline as your exposures and conversions.

// after the LLM call
flagsmith.trackEvent('cost', {
  identifier: user.id,
  value: usage.costUsd,
  metadata: { feature, variant, plan },
})
Step 2

See net margin per cohort

Exposures, conversions and cost are joined by identity and trait, so you see which variant and which cohort earn or burn.

pro · ai_summary+$252
free · ai_summary−$489
Step 3

Approve a segment override

FlagLedger drafts the rule. You approve it with your own Flagsmith account, so the audit log shows who changed what.

+ segment  free_tier_cost_guardrail
    plan EQUAL "free"
+ override search_bar_mode
    {"mode":"ai_summary","daily_quota":2}
Self-host

Running next to Flagsmith in minutes.

One Compose file starts Flagsmith, its task processor, Postgres and FlagLedger. A one-shot setup creates the project, flag, metrics, warehouse connection and experiment for you. No ClickHouse, no Kafka.

$ git clone <this repo> && cd flagledger
$ cp .env.example .env    # set secrets
$ docker compose up -d
  flagsmith          healthy   :8000
  flagledger-init    done      experiment running
  flagledger         ready     :3000
FAQ

Questions

Do I need Flagsmith Cloud?

No. FlagLedger is built for open-source, self-hosted Flagsmith with Experimentation enabled. Events stay in Flagsmith’s own Postgres.

Where do cost numbers come from?

Your app sends them as a `cost` event after each paid call, using the token usage and your price table. The NoteFlow example uses simulated traffic, but its price per AI search is measured: FlagLedger runs the real feature through Claude and prices each call from the token bill ($0.0127 on Opus 5.5, $0.00036 on Haiku 5.5).

Will it change my flags without asking?

Never. FlagLedger only drafts the override. Nothing is written to Flagsmith until a signed-in person approves it, using their own account.

Does it work with any flag?

Any multivariate flag whose events carry the feature, variant and plan in metadata. NoteFlow search is the sample.

Before you ship the winner, check the bill.

Get startedSign in