Case study

MarginFront

Today an AI founder can't easily tell which customers make money, because what a model call costs and what the customer was charged sit in different systems, so MarginFront meters every call, ties it to the customer and carries it into the month's close.

Role
Co-founder · Head of Product · sole builder
Timeline
Jan 2026 → present (core is open source)
one line of proof
Sole builder · core platform open source

90-second version

  • AI companies charge for outcomes and pay for tokens, and because the two numbers live in different systems, it's hard for a founder today to say which customers are profitable.
  • I built the platform end to end, so it meters every model call across 1,100+ models and tools, ties each one to what the customer was charged and closes the month into a locked, balanced journal.
  • I built it with design partners, and the core platform is now open source so any AI team can run its own margin math, while the custom integration work companies pay for runs on a private fork I build per client.
Live margin by agent: every agent's tasks, cost, what it earned, and its margin over the last thirty days.
Exhibit MF-1Live margin by agent: every agent's tasks, cost, what it earned, and its margin over the last thirty days.
Stack
React · Node / npm · Python · Neon · Vercel · Claude · Sentry · PostHog · Linear · Cloudflare · Pipedream · Stripe on one feature
01

Problem

One prospect report burns a search call, an LLM call, and an email send. The customer sees one line on the invoice. Those two facts live in different systems, so the question that decides the company (which customers are we making money on) has no answer anyone trusts. Founders price off a hunch, over-serve their heaviest accounts, and find out at the close that the plan that won the deal loses money every time it runs. Then the books get built by hand, because the finance stack was designed for seats and subscriptions, and a model call that costs a different amount on Tuesday.

02

Non-obvious insight

The hard part of pricing an agent product is attribution, which means putting one agent call, its model cost, its tool costs, its customer and its invoice line in a single row, and once they sit together the pricing model falls out of the table. The billing unit is whatever the customer reads on the invoice, and everything else in the product is built around that choice. Bill by the report and a 15-page report is one billable event, and bill by the page and the same call is 15, so the same work at the same cost lands on a different invoice. Build the attribution layer first and margin by customer, margin by agent, and what the month closes at all become queries instead of projects.

03

Bets I made

  • The unit of analysis is the agent call, and customers and months are ways of adding calls up.
  • Attribute cost the moment the event comes in, because chasing it at month end is where startups get this wrong.
  • Stay product-agnostic and model-agnostic on purpose: one catalog of 1,100+ models and tools, LLM and not, so a team that swaps providers keeps its margin history. Cost tracking, revenue attribution, the books, and AI ROI across the company sit in one table, whether the unit is a single usage event or a long chain of services billed as one outcome.
  • Integration is the funnel. An npm package for your own engineers' coding-agent spend, an SDK and REST API for the code your customers pay for, an MCP server for everything else. A customer who never opens the site is still a customer.
  • Run the company on the same kind of agent fleet the product bills for. Every feature goes out through a line of specialist agents, gated by a human ✓ in Slack. The whole fleet is documented at /agents.
  • Open the core and sell the fit. Metering and attribution get better the more teams run them against real provider data, so the core goes public, and the work companies pay for, wiring it into their own billing, books and agent stack, runs on a private fork I build one client at a time.
04

What shipped

  • Every model call priced from the provider's own usage data and tagged to the agent, the customer, the task, and the model. One event can carry a whole chain of services and still bill as one outcome.
  • A close you can lock: charges classified to a chart of accounts, the month sealed, a balanced journal out the other side. Invoices collect through Stripe or PayPal; the journal exports to QuickBooks or NetSuite. Four labels of revenue (Agent-Earned, Revenue, Billed, Collected), each with its own margin, so the founder and the accountant stop meaning different things by the word revenue.
  • Three doors in: the code-cost-clarity npm package for your team's own Claude Code and Codex spend, the SDK and REST API for the product your customers pay for, the MCP server for running the whole account from an AI assistant without opening the site.
One event drilled down: the model, tokens by type with the cost of each line, the total, and the raw properties the SDK sent.
Exhibit MF-2One event drilled down: the model, tokens by type with the cost of each line, the total, and the raw properties the SDK sent.
The month-end close: usage events recorded, costs mapped to GL codes, COGS split from R&D, mismatches fixed, then sign-off. A closed month freezes.
Exhibit MF-3The month-end close: usage events recorded, costs mapped to GL codes, COGS split from R&D, mismatches fixed, then sign-off. A closed month freezes.
05

Evals and instrumentation

Every attributed call ties back to a provider's own usage line, within a stated tolerance, before it reaches a dashboard. Margin reconciles against Stripe at the monthly close. Events never drop: each one lands priced, or flagged as waiting on a model the catalog hasn't learned yet, or flagged as missing the token counts, and the dashboard says which. Where there is no priced usage, the number reads blank rather than $0, because a zero that isn't real is the kind of thing an auditor finds three months later. The fleet that ships the product gets graded too: the Coach agent scores the pipeline against a 120-point rubric on the 1st and 15th.

MFiQ, the financial hygiene score: rules first, zero tokens spent, and the AI insights held back until the books are clean.
Exhibit MF-4MFiQ, the financial hygiene score: rules first, zero tokens spent, and the AI insights held back until the books are clean.
06

What broke

The first builds tried to model every provider's billing quirks up front. One provider worked and two was harder, and by three the abstraction was worse than the problem it replaced. The fix was to stop pretending providers agree with each other: take each one as a raw feed, keep its own rates as the source of truth, and normalize once at the attribution layer. That is also why the model catalog is a table you can query, so adding a model never means a redeploy. Second failure: margin dashboards nobody opened, because they lived somewhere the founder wasn't. The daily margin digest now lands in Slack.

07

What's next

The core is open source at github.com/MarginFront-Open/MF-Open, and I'll keep refining it in public. The plan-recommendation loop that reads the last 30 days of attributed events and proposes the pricing model goes onto the private fork first, because that's the piece a client is paying to have wired into their own stack, and teams who want it can ask for it.

Talk to me

Ask me how any of this works.

The fleet, the pricing, the closes. Fifteen minutes, on the calendar.