TypeScript SDK · Python SDK · HTTP API
Marginal tracks the cost of every LLM call and slices it by the fields you care about — customer, feature, model.
npm install marginal-sdk · pip install marginal-sdk
The dashboard
Slice spend by what matters in your product, see every dimension charted automatically, and check exactly what your integration sent.
How it works
npm install marginal-sdk, pip install marginal-sdk, or no install at all — POST JSON to the HTTP API from any language. The SDKs are zero-dependency, buffered, fire-and-forget: track() never throws and never blocks your request path.
Name the provider, paste the response's model and usage as-is — Marginal detects the usage shape and computes the cost server-side against a daily-synced model price catalog.
Group and filter by customer, feature, model — any field you register. Save the views you keep coming back to.
import { Marginal } from "marginal-sdk";
const marginal = new Marginal({ apiKey: process.env.MARGINAL_API_KEY });
const response = await openai.chat.completions.create({ /* … */ });
marginal.track({
provider: "openai",
model: response.model,
usage: response.usage,
fields: { customer: "acme-corp", feature: "support-bot" },
});The cost lands computed, priced at that day's catalog rates — no token math in your codebase.
Cost observability
Register your vocabulary — customer, feature, anything you slice by — then group or filter spend by it. Unregistered keys are stripped and reported back, so dashboards stay clean.
Send provider, model, and the response's usage object; cost is computed server-side from a daily-synced price catalog, with per-project overrides. Prices are frozen at ingest.
Any Explorer state — range, filters, group-by — saves as a named view. The questions you ask every week are one click away.
TypeScript and Python, zero dependencies. Events buffer locally and flush in batches in the background; network failures retry and then warn — your app never notices. Prefer no SDK? The HTTP API is a single JSON POST.
Paste marginalhq.com/llms.txt into Claude Code, Cursor, or any coding assistant and it has everything it needs to wire up Marginal — or follow the per-provider recipes yourself.
Create a project, register your fields, drop in one track() call. Your next deploy starts answering questions.