Core Concepts
MarginFront watches what your AI agents do, tracks what it costs you, and bills your customers. That’s it. Everything below is just naming the moving parts.The building blocks
1. Agent
Your AI product. The thing that does work for your customers. A customer support bot is one agent. A research assistant is another. A document analyzer is a third. If you only sell one product, you have one agent. If you sell three products that price differently, you have three agents. Each agent has a code (a short handle you pick, likecs-bot or research-v2). You use this code when logging usage events — it tells MarginFront which product did the work. You create agents in the dashboard.
2. Customer
Who you’re billing. One of YOUR end users or companies. Each customer has an externalId — the user ID from your own system (likeacme-001 or user_847). This is how MarginFront connects usage events to the right customer without you having to memorize MarginFront’s internal UUIDs.
You can create customers through the dashboard, the API, the SDK, or the MCP tool.
3. Signal
What you measure. A deliverable or outcome your agent produces. Good signals (things your customer cares about):messages— messages sent by a chatbotreports-generated— full reports producedpages-processed— document pages analyzed
gpt-4o-call— that’s an internal cost, not a deliverableapi-requests— too technical, doesn’t map to value
4. Event
A record that something happened. This is the core data type — everything else is built from events. An event says: “Agentcs-bot sent 1 message for customer acme-001 using gpt-4o from openai, consuming 523 input tokens and 117 output tokens.”
You log events by calling POST /v1/usage/record (or mf.usage.record() with the SDK). This is the endpoint your code calls all day, every day once you’re live. Everything else — costs, revenue, invoices, margins — is calculated from these events.
5. Service Costs
Calculated automatically. You don’t set these. When you log an event with a model and provider (likegpt-4o from openai), MarginFront looks up the token pricing in its built-in table of 300+ LLM models. It multiplies your input tokens by the input price, your output tokens by the output price, and stores the result as the service cost for that event.
Your customers never see service costs. They’re for YOUR margin dashboard — so you can answer “how much did it actually cost me to serve this customer this month?”
If MarginFront doesn’t recognize the model you sent, the event still saves — but with cost = null (not zero, not dropped). You can map the unknown model to a known one in the dashboard, and MarginFront backfills the cost retroactively. Events are never thrown away.
6. Pricing Plan
Turns your costs into prices. This is where you decide what to charge. A pricing plan sets the rate per unit of each signal. “I charge 2.00 per report.” Think of it like the “Starter Plan” or “Pro Plan” you’d show on your pricing page. Created in the dashboard, tied to an agent.7. Subscription
Ties a customer to an agent through a pricing plan. “Starting April 1, bill Acme Inc for thecs-bot using the Starter Plan, on a monthly billing cycle.”
Without a subscription, MarginFront still tracks costs (what things cost you), but it can’t calculate revenue (what you charge the customer) or generate invoices.
8. Invoice
Auto-generated at the end of each billing cycle from a subscription’s usage. Shows line items per signal with quantity and price. Example: “Messages: 150 x 15.00.” The customer sees what they used and what they owe. You see what it cost you, what you charged, and the margin.9. API Key
Your credential for talking to MarginFront’s API. Starts withmf_sk_ (secret key — server-side only, full access).
The API key identifies your organization — you never need to pass an org ID in your requests. Created in the dashboard under Developer Zone > API Keys.
Never put your secret key in frontend code or commit it to git.
The metric vs service cost mental model
Signals are what your CUSTOMER sees. Service costs are what YOU see. A customer sees their invoice:Messages: 150 x $0.10 = $15.00You see your margin dashboard:Messages: 150 events, $2.34 LLM cost, $15.00 revenue, 84% marginSame events, two perspectives. Signals face outward (billing). Service costs face inward (profitability).
Pricing Strategy Types
A pricing strategy is one specific rule inside a pricing plan. Every strategy has a charge type that decides WHEN the customer is billed and a pricing model that decides HOW the number is calculated.Charge types (when to bill)
There are four charge types. Each answers a different question.| Charge type | When it fires | Example |
|---|---|---|
usage | Every time an event comes in. Priced per unit of a signal. | ”Charge $0.10 per message, after it’s sent.” |
recurring | Once per billing cycle, whether the customer used anything. | ”Charge $99 on the first of every month.” |
seat_based | Once per billing cycle, priced by seatsCount on the sub. | ”Charge 50/month.” |
onetime | Once, on the subscription start date. Never again. | ”Charge $500 setup fee when the customer signs up.” |
Pricing models (how to calculate)
Usage strategies route through one of four pricing models.flatSimple rate per unit.quantity × rate.graduatedTiered with progressive rates. Units 1 to 10 at one rate, 11 to 50 at another, 51+ at a third. Each unit pays the rate for ITS tier.volumeTiered with one rate for all units. All units pay the rate of the tier the TOTAL quantity landed in.credit_poolFlat fee for a pool of units. Per-unit overage after the pool is used up. Often called “commitment + burst.”
Per-window-aggregate billing
Usage strategies bill on the TOTAL quantity for the window, not per event. That means:- One event with
quantity: 1500bills identically to three events withquantity: 500each. - MarginFront adds up all the events in the billing period, feeds the total through the pricing model, and produces one invoice line.
Cost-only metrics
You can skip pricing entirely. If a signal has no pricing strategy linked to it, events still come in and cost still tracks, but the revenue contribution for that signal is zero (not unknown, not missing: explicitly zero). Useful for:- Tracking infrastructure costs you don’t pass through to customers.
- Shadow-logging new signals you haven’t decided how to price yet.
- Internal tool usage that’s part of your operating cost, not a line item.
The four labels of revenue
MarginFront reports four different dollar amounts for “revenue,” each answering a different question. They are NOT the same number. Know which one you’re looking at.Agent-Earned
What your agents produced this period, at the pricing strategy rates. No fees, no proration. Formula: every usage event in the window, multiplied by the rate for its pricing strategy, summed up. Use it to spot activity trends early. Agent-Earned goes up the moment an event fires. No need to wait for invoices to finalize.Revenue
The full formula. What the customer owed you for the period. Agent-Earned plus recurring fees plus seat fees plus onetime fees (all prorated if the subscription only partly overlapped the window). Use it for “what did we earn this month, invoiced or not.”Billed
What you actually invoiced. Issued invoices, waiting on payment. Sum of every invoice with statusissued or overdue that was dated in the window. Draft invoices don’t count here. Paid invoices don’t count here (those move to Collected).
Use it for A/R tracking.
Collected
Cash landed. Invoices marked paid. Sum of every invoice with statuspaid that was dated in the window.
Use it for cashflow.
Why four?
Because they answer different questions and they come out in that order:- Agent does work. Agent-Earned goes up.
- Billing cycle ends. An invoice finalizes. Billed goes up.
- Customer pays. Collected goes up.
Choosing your signal name and quantity
Before you write a single line of code, you have one decision to make: what unit do you want your customer to see on their invoice? That answer becomes your signal name. Everything else falls out of it. Four rules cover the whole thing:- Fire one event per business outcome. When a report finishes, that’s ONE event. When a call ends, that’s ONE event. Not one per page, not one per minute, not one per token. MarginFront is not a streaming meter — it’s a “something happened” logger.
-
The signal name IS the billing unit. Bill per page? Name it
pages. Bill per report? Name itreports. Bill per minute? Name itminutes. Whatever word shows up on your invoice is what you type intosignalName. -
quantityis the count of that billing unit for this one event. A 50-page report fired aspageshasquantity: 50. The same report fired asreportshasquantity: 1. Same LLM call underneath, same cost, different invoice line. -
Cost and revenue are decoupled. MarginFront calculates your cost from
model+modelProvider+ tokens automatically. Your revenue isquantity × your pricing plan rate. The gap is your margin.
| Signal name | Quantity | Rate per unit | What the customer sees on the invoice |
|---|---|---|---|
reports_generated | 1 | $50.00 per report | ”1 report × 50.00” |
report_pages | 50 | $2.00 per page | ”50 pages × 100.00” |
tokens_used | 15,000 | $0.01 per 1K | ”15,000 tokens × 0.15” |
Fire one event per outcome. Not one per page, not one per minute. This is the single easiest thing to get wrong. If your agent writes a 50-page report, send MarginFront ONE event withWhen in doubt, pick the signal name your customer would say out loud if you asked them “what am I paying for?” That word is the name. See Example 3 in Tracking Events for the exact code pattern, and the Signals API reference for the full signal API.quantity: 50— not 50 events withquantity: 1. The point of thequantityfield is that you don’t have to loop. Looping would multiply your bill, flood your analytics, and burn API calls for no reason.
Setup sequence (the golden path)
Here’s the order things happen, from zero to fully working:Three integration paths
You can send events to MarginFront three different ways. Pick whichever fits your workflow.SDK (recommended for Node.js apps)
REST API (any language)
Same event endpoint (POST /v1/usage/record), raw HTTP. Works from any language or platform — Python, Go, Ruby, curl, whatever. Pass your API key in the x-api-key header. See the Usage Events reference for the full field reference.
MCP (for AI coding assistants)
Same API, but your AI coding assistant (like Claude Code or Cursor) calls it for you. Useful for setting up agents, customers, and signals without leaving your editor. See the MCP Setup guide for details.Next steps
- Quickstart — Go from nothing to a logged event in 10 minutes
- OpenAI recipe — Wire MarginFront into an OpenAI-powered app
- Anthropic recipe — Wire MarginFront into an Anthropic-powered app
- Non-LLM recipe — Track SMS, web scraping, PDF generation, and other non-LLM tools
- Usage Events reference — The full field reference for the event endpoint

