Quickstart: fire your first event in under a minute
You don’t need to set anything up first. When you fire an event with a newThis guide takes you from zero to a real usage event visible in the dashboard. The first three steps are all you need for cost tracking. Step 4 is optional for revenue tracking and invoicing. We use plain curl so the examples work regardless of language. The Node SDK and MCP versions are at the bottom. Every curl example on this page comes in two versions: Bash (macOS, Linux, WSL, Git Bash) and PowerShell (Windows). Pick the tab that matches your terminal. The two are not interchangeable, and copying the Bash version into PowerShell is the most common cause of a 401 with a perfectly good key. Commands that are identical in both shells, likecustomerExternalId,agentCode, orsignalName, MarginFront creates the customer, agent, or signal automatically. Your existing user IDs from your own database flow straight through. The dashboard updates the moment the event lands.
npm install, appear once.
1. Get an API key
In the MarginFront dashboard, go to Build → API keys and create a key pair (or use a secret key you already saved). Copy the secret key (looks likemf_sk_test_...) the moment it’s shown — you can’t see the full value again after the first time.
Put it in an environment variable:
Windows: theThe variable lives only in the terminal window you set it in. Open a new window and you set it again. To make it permanent on Windows, use System Properties → Environment Variables, or run$env:prefix is not optional. PowerShell reads$MF_API_SECRET_KEYas a variable it has never heard of, substitutes an empty string, and sends a request with no key. The API answers401, which reads like a bad key even though the key is fine. Write$env:MF_API_SECRET_KEYevery time you reference it.
setx MF_API_SECRET_KEY "mf_sk_your_key_here" once and open a new terminal.
The API key alone identifies your organization. You don’t need to pass an org ID anywhere.
The production API base URL is https://api.marginfront.com. All examples below use it.
2. Fire your first usage event
This is the only call you need to integrate MarginFront. Three of the fields use IDs from your own system. MarginFront creates the customer, agent, and signal on the spot if they don’t exist yet.You invent these three IDs. Nothing has to exist in MarginFront first.test_user_001,report_writer, andreport_generatedbelow are values made up for this example. Send whatever strings you like, as long as you keep using the same ones for the same customer, agent, and signal. The records get created on the first event that mentions them.
Windows: three more things that bite.Field semantics:
- Use
curl.exe, notcurl. In Windows PowerShell,curlis an alias forInvoke-WebRequest, a different command whose parameters do not match curl’s. It fails with a parameter error. Spelling outcurl.exeruns the real curl that ships with Windows 10 and later.- Put the JSON in a here-string. The
@'and'@markers quote the block literally. The closing'@has to sit at the very start of its own line or PowerShell will not end the string.- Pipe the body in rather than passing it as an argument.
$body | ... -d '@-'hands the JSON to curl on standard input, and'@-'is curl’s name for standard input. Writing-d $bodyinstead breaks on Windows PowerShell 5.1 and on PowerShell 7.0 through 7.2. Those versions strip the double quotes out of any argument containing spaces, so curl receives{records: [...]}and the API rejects it. Piping avoids that entirely and works on every version.
customerExternalIdis your own ID for this user. In real code that’s the ID your database already uses (e.g.usr_abc123). For a first test, any string works.agentCodeis a stable name for the agent doing the work (e.g.report_writer).signalNameis what the agent did (e.g.report_generated).modelandmodelProviderare required so MarginFront can look up that model’s input and output token rates.
What models does MarginFront recognize? The catalog has 1100+ entries across LLM and non-LLM services (Cloud Run, Twilio, Google Places, etc.). To discover the canonical name for your service, list the catalog: GET /v1/services?provider=<your-provider>. See the Services Catalog reference for the full endpoint and the Supported Services overview for what’s covered. If your service is in the catalog, fire events with the canonical name and cost auto-resolves on ingest. If not, the event still lands but cost stays null until the catalog is updated.
The endpoint references the customer and agent by their string IDs, not their UUIDs.
What you should see:
successful: 1, you just logged a real event and three records were created behind the scenes for you.
3. Look at the dashboard
Log into app.marginfront.com and open the Home page. You should see one event with the customer, agent, signal, model, and calculated cost. The customer, agent, and signal you sent are now real records in your dashboard. You can also fetch the same data via the API:& is reserved there. Unquoted, Windows PowerShell 5.1 refuses the line outright (“The ampersand (&) character is not allowed”), while PowerShell 7 cuts the command at the &, runs the truncated URL as a background job, and errors on the leftover text.
What just got created
When the event landed, MarginFront did three things automatically:- Customer. Created from the
customerExternalIdyou sent. The displaynamedefaults to the same string, so you may seetest_user_001in the customer column at first. Rename it later in the dashboard or via the customers API. - Agent. Created from the
agentCode. Displaynamedefaults to the same string. - Signal. Created from the
signalName. Displaynamedefaults to the same string.
customerExternalId rolls up under that customer. Same for agents and signals.
What does not auto-create:
- Pricing plans and subscriptions (Step 4 below, optional).
- Invoices.
- Team members.
4. Add revenue tracking (optional)
Skip this step if you only need cost tracking. Without a pricing plan, MarginFront still tracks costs. It just won’t generate revenue numbers or invoices. To track revenue, you need two things:- A pricing plan that defines per-unit charges.
- A subscription that ties one of your customers to that plan.
Same thing, using the Node SDK
If your app is Node.js, install the SDK:Same thing, using MCP
MCP lets you ask Claude, Gemini, or ChatGPT to operate on your MarginFront account in plain English. Use it for backfills, batch operations, queries, and admin actions. MCP is not how you instrument your product. For per-event tracking from your own code, use the curl or SDK examples above. To connect MCP, add this to.mcp.json in your project root:
"Show me MarginFront usage analytics for today" or "Find the customer with external ID test_user_001". See MCP Setup Guide for the full tool list.
You’re done
You just shipped a working integration. Suggested next steps:- Wire this into real code. Call
/v1/usage/record(ormf.usage.record(...)) from your product code every time work happens. - Batch high-volume traffic. The endpoint accepts up to 100 records per call.
- Track multi-service events. When one outcome uses several services (search + LLM + email, for example), pass a
services[]array on the request body. See the SDK tracking-events guide, Example 5. - Add revenue tracking. When you’re ready to bill, follow Step 4 above.
- Read the usage-events reference. Full field list and what happens when a model isn’t recognized.
Help, something didn’t work
Got a 401 on Windows with a key you know is good? Check these three in order. Each one sends an empty or malformed key and produces the same 401.- You wrote
$MF_API_SECRET_KEYinstead of$env:MF_API_SECRET_KEY. - You ran
curlinstead ofcurl.exe, so PowerShell usedInvoke-WebRequest. - You set the variable in a different terminal window than the one you are calling from.
$env:MF_API_SECRET_KEY.Length. A number means it’s set. A blank line or an error means it isn’t, and the request went out with no key.
Cross-reference the response body with errors.md. Still stuck? Email [email protected] with:
- The curl command (API key REDACTED, never share it).
- The full response body you got back.
Where else to look
- Discover canonical model names: Services Catalog | Supported Services overview
- Full page index: https://docs.marginfront.com/sitemap.xml
- LLM-friendly reference: https://docs.marginfront.com/llms.txt
- MCP-specific reference (for AI assistants connecting via MCP): https://marginfront.com/llms-mcp.txt

