Skip to content
Margin
ProductThe Meterevery call, meteredThe Estatethe org chart of your agentsThe Money Mapwhere the spend goesThe Parity Gateprove it before it shipsThe Governorthe control loopDocsPricingCompany
Sign inGet set up →
ProductThe MeterThe EstateThe Money MapThe Parity GateThe GovernorDocsPricingCompanyLive demoSign in

Two plugs in, one key out

Margin measures what your agents spend and what it bought. You connect two things, your LLM calls and your evals, and the key that writes them also lets your agents read Margin over MCP.

Last updated 23 September 2026

Before you start

  • Margin is a meter, not a proxy. Your agents call OpenAI, Anthropic and the rest directly; the SDK reads token counts off the response after it returns. We are never in your request path.
  • It is fail-safe. An emit never raises into your request path. In Python, rows are buffered, so ok=True means queued, not stored: a row that fails to land, a bad key included, prints one warning and is counted in delivery_stats(). The published npm 0.2.0 sends each row as it happens and returns { ok: false } when one fails; the buffer and deliveryStats() are in the repo build. The meter cannot take down the thing it measures.
  • No third-party dependencies. Importing the Python SDK loads nothing outside the standard library.
  • MCP does not replace the SDK. An MCP server is a tool your agent calls; it cannot observe the token counts on a call it was not part of. The SDK writes, MCP reads.
Contents
  • Plug 1 — your calls in
  • Plug 2 — your evals in
  • MCP for your agents
  • Roll out from staging
  • What it does not do yet
Contents
  • Plug 1 — your calls inHow do I meter?
  • Plug 2 — your evals inWhat is an outcome?
  • MCP for your agentsCan agents query it?
  • Roll out from stagingHow do I start safely?
  • What it does not do yetWhat is missing?
Get a key →

Plug 1 — your calls in

Install, point it at your deployment, and instrument one workflow. The key comes from /start, issued on the spot.

shell
pip install margin-meter
export MARGIN_INGEST_URL="https://trymargin.io"
export MARGIN_INGEST_KEY="mgk_…"

Then wrap the calls in the one workflow you are measuring. instrument_all monkeypatches the installed OpenAI, Anthropic and Gemini SDKs and hooks litellm, so a whole repo is a few lines:

python
from margin_meter import MarginMeter, instrument_all

meter = MarginMeter()  # reads the two env vars above
instrument_all(meter, workflow_id="support-triage")

A TypeScript SDK has the same shape (npm install margin-meter), but the npm package trails the repo: the eval adapters below are not in a plain npm install yet. /start sets you up on what is published.

Instrument one workflow, not everything. A workflow with no defined outcome floods the meter with calls that can never resolve to a cost-per-outcome, and the denominator is the whole measurement.

Plug 2 — your evals in

The outcome is the number everything else divides by, and only you can define it: a merged PR, a passed eval, a resolved ticket. If a harness already grades the workflow, an adapter reads the results file it writes anyway and records one outcome per graded case, pass or fail, with its grading stated.

We divide by the outcomes you define, so if your evals are generic, so is the denominator. The console shows what graded them, and flags a suite that passes or fails nearly every case, because that suite cannot rank two routes.

Adapters ship for promptfoo · Braintrust · LangSmith · Ragas · deepeval · Langfuse · pytest · vitest / jest.

A skipped or errored case is never counted as a verdict, and no adapter adds a harness of ours to your suite. If you have no eval harness, report it directly:

python
meter.record_outcome(workflow_id="support-triage", passed=True)

MCP — let your agents query Margin

Margin runs an MCP server over JSON-RPC 2.0. Point any MCP client at it with your ingest key. The key resolves to that project’s own rows, so an agent sees your estate and nobody else’s.

http
POST https://trymargin.io/api/mcp
Authorization: Bearer mgk_…
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/call",
 "params":{"name":"margin_parity_prior",
           "arguments":{"task_class":"extraction"}}}

GET /api/mcp returns the server descriptor and every tool schema, so a client can discover the surface without credentials.

The one worth building against

margin_parity_prior answers a question an agent can act on before it spends: for this kind of work, how often has a cheaper model already held outcome parity? Margin stops being a page you read and becomes a thing your agents consult at runtime.

Let a coding agent do the integration

margin_instrument_plan returns the exact edits for your language and the command that verifies them, so Claude Code or Cursor can do install → instrument → verify without you writing any of it.

⛔ It does not scan your repository, and it says so. Margin’s server runs on Margin’s infrastructure and cannot see your code — a plan that implied otherwise would be a guess your agent would act on. The scan runs where the code is:

shell
python -m margin_meter.doctor --json

doctor is pure stdlib, makes no network call and never imports your modules. It lists every provider call site and whether the meter covers it, fail-closed: a gap it cannot prove covered is reported. It exists because of a real bill where 3 of 6 call sites were unmetered and carried all of the cache-write spend. In Python the plan is one edit at the entrypoint, because instrument_all is global; TypeScript instruments per client, so it touches every file that constructs one.

Read tools

margin_portfolio_summaryhow many projects exist, how many emit real economics
margin_portfolio_economicscross-project spend, cost-per-outcome, savings at stake
margin_fix_this_firstthe ranked highest-$-impact opportunities across the estate
margin_list_projectsevery project and its connection state
margin_project_economicsone project: spend, cost-per-outcome, token yield, retry tax
margin_project_money_mapone project's workflows as spend-blocks, with the node-flow
margin_project_recommendationsthe recommendation feed, biggest-$-impact first
margin_activity_logmeasured calls, outcomes and closed-loop actions, in time order
margin_parity_priorfor a task class: how often a cheaper model has held parity
margin_lever_librarythe catalogue of safe-gated optimisation levers
margin_power_projectionthe projected date to the parity confidence floor (88 all-passing trials, the Wilson 95% lower-bound sample size — not statistical power) at the current cadence
margin_agent_marginsspend change split into agent headcount vs per-agent intensity
margin_cost_per_outcome_decompositionblended unit-cost change split into within vs between
margin_baumol_assurance_trendthe rework share of unit cost, over time
margin_roi_summarythe parity-gated ROI proof for the estate
margin_flow_roione flow's before-bill, proven route, and counterfactual after-bill
margin_instrument_planthe exact edits to instrument a repo, and the command that verifies them
margin_stage_planper-STEP model, effort, context, length and retry advice, at the bar your chain length demands
margin_config_half_lifehow fast a tuned config is going obsolete — the half-life of its outcomes-per-dollar

Act tools, and why you cannot call them over HTTP

These three close the loop. They are fail-closed over HTTP — GET /api/mcp reports act_enabled: false — and are served only on the local stdio transport with an operator’s sign-off.

margin_approve_recommendationpending → approved. Ratifies; enacts nothing.
margin_apply_recommendationadopt a proven route and re-measure before → after.
margin_revert_recommendationback an adopted route out. Requires a reason.

⛔ Margin has no mechanism to change your routing. There is no endpoint that tells your code which model to run. We publish a decision, promote, hold or revert, and your code applies it or ignores it. The parity gate and the revert rule are ours; the switch is yours.

Start in staging. Three rungs, stop at any of them

1. StagingA separate project and key, with environment=staging. Because source is forced server-side to the key’s project, a staging key cannot read or write production rows. Zero production exposure — production is not instrumented yet.
2. Production, meter onlyThe same SDK with a production key. Still zero production effect — we only record what already happened. Staging traffic is not representative of a bill, so this is where the number becomes real.
3. ActApply a published decision in your own code. Nothing moves until you do.

What this does not do yet

An account starts empty. Signing up is an email: the sign-in link creates the account, and a key is issued on the spot. What it cannot do alone is say what an outcome IS. If you run evals, they are the definition. If you don’t, someone has to agree with you on one before a cost-per-outcome means anything.

No SOC 2, no ISO 27001. We are pre-revenue with no customers yet, and claiming a certification posture we do not have is the fastest way to deserve none of your trust.

No value is ever invented. value_usd is filled only by you. Supply nothing and every figure Margin computes is cost per outcome, labelled as one.

The full field list, every column and which ones are free text you choose, is on /security. Questions go to the founder: subh@trymargin.io.

Margin

The economic control layer for your AI workforce. Price an outcome and Margin reports what it returns; a cheaper route ships only when quality holds. Neutral across providers, and every number on this site traces back to a run we can show you.

Product

  • The five parts
  • Console
  • Docs
  • Pricing
  • Compare

Company

  • About
  • Build log
  • Security
  • Contact

Resources

  • How it works
  • Day 0 to 60
  • Essays
  • margin-cost on GitHub
  • margin-meter on PyPI
  • margin-meter on npm

Legal

  • Terms
  • Privacy
  • Cookies
  • DPA
© 2026 MarginBuilt in Chicago41.88° N, 87.63° W