{"slug": "show-hn-marginal-see-which-customers-and-features-drive-your-ai-api-costs", "title": "Show HN: Marginal – See which customers and features drive your AI API costs", "summary": "Marginal, a new cost-observability tool for AI API usage, launched with TypeScript and Python SDKs plus an HTTP API, enabling developers to track the cost of every LLM call and slice spend by customer, feature, or model. The tool computes costs server-side against a daily-synced price catalog, flags unpriced models instead of averaging them away, and integrates via a single track() call per request. Marginal aims to answer 'why was the bill that high?' by automatically charting spend across dimensions and logging every API request outcome.", "body_md": "TypeScript SDK · Python SDK · HTTP API\n\n# See where your AI spend goes.\n\nMarginal tracks the cost of every LLM call and slices it by the fields you care about — customer, feature, model.\n\nnpm install marginal-sdk · pip install marginal-sdk\n\nThe dashboard\n\n## From “the bill doubled” to a named cause\n\nSlice spend by what matters in your product, see every dimension charted automatically, and check exactly what your integration sent.\n\n### Spot the spike without building a chart\n\nInsights charts spend for every dimension automatically — each model, provider, and registered field gets its own chart. No setup, no query builder.\n\n### Know exactly what landed\n\nEvery API request is logged with its outcome — accepted counts, rejected events and why, stripped keys, unpriced models. Debug your integration without guessing.\n\n### Never a silent $0\n\nUnknown model? The event still lands, flagged as unpriced — visible in the dashboard and the API response, never averaged away. Set a custom price and it applies at ingest.\n\nHow it works\n\n## One call per LLM request. That's the whole integration.\n\n- 1\n### Pick your connection\n\n`npm install marginal-sdk`\n\n,`pip install marginal-sdk`\n\n, 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. - 2\n### Track each LLM call\n\nName the provider, paste the response's\n\n`model`\n\nand`usage`\n\nas-is — Marginal detects the usage shape and computes the cost server-side against a daily-synced model price catalog. - 3\n### Slice your spend\n\nGroup and filter by customer, feature, model — any field you register. Save the views you keep coming back to.\n\n``` js\nimport { Marginal } from \"marginal-sdk\";\n\nconst marginal = new Marginal({ apiKey: process.env.MARGINAL_API_KEY });\n\nconst response = await openai.chat.completions.create({ /* … */ });\n\nmarginal.track({\n  provider: \"openai\",\n  model: response.model,\n  usage: response.usage,\n  fields: { customer: \"acme-corp\", feature: \"support-bot\" },\n});\npython\nimport os\n\nfrom marginal import Marginal\n\nmarginal = Marginal(api_key=os.environ[\"MARGINAL_API_KEY\"])\n\nresponse = client.chat.completions.create(...)\n\nmarginal.track(\n    provider=\"openai\",\n    model=response.model,\n    usage=response.usage.model_dump(),\n    fields={\"customer\": \"acme-corp\", \"feature\": \"support-bot\"},\n)\ncurl -X POST https://api.marginalhq.com/v1/events \\\n  -H \"Authorization: Bearer $MARGINAL_API_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"events\": [\n      { \"provider\": \"openai\",\n        \"model\": \"gpt-4o-2024-08-06\",\n        \"usage\": { \"prompt_tokens\": 2006, \"completion_tokens\": 300 },\n        \"fields\": { \"customer\": \"acme-corp\", \"feature\": \"support-bot\" } }\n    ]\n  }'\n```\n\nThe cost lands computed, priced at that day's catalog rates — no token math in your codebase.\n\nCost observability\n\n## Built to answer “why was the bill that high?”\n\n### Slice by any field\n\nRegister 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.\n\n### LLM-aware pricing\n\nSend 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.\n\n### Saved views\n\nAny Explorer state — range, filters, group-by — saves as a named view. The questions you ask every week are one click away.\n\n### SDKs that stay out of the way\n\nTypeScript 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.\n\n## Let your coding agent do the integration\n\nPaste [marginalhq.com/llms.txt](/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.\n\n[Integration recipes](/docs/integrations)\n\n## From zero to a live spend dashboard in five minutes.\n\nCreate a project, register your fields, drop in one track() call. Your next deploy starts answering questions.", "url": "https://wpnews.pro/news/show-hn-marginal-see-which-customers-and-features-drive-your-ai-api-costs", "canonical_source": "https://marginalhq.com/", "published_at": "2026-08-19 13:23:17+00:00", "updated_at": "2026-08-19 13:44:29.187554+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-infrastructure"], "entities": ["Marginal", "OpenAI", "Claude Code", "Cursor"], "alternates": {"html": "https://wpnews.pro/news/show-hn-marginal-see-which-customers-and-features-drive-your-ai-api-costs", "markdown": "https://wpnews.pro/news/show-hn-marginal-see-which-customers-and-features-drive-your-ai-api-costs.md", "text": "https://wpnews.pro/news/show-hn-marginal-see-which-customers-and-features-drive-your-ai-api-costs.txt", "jsonld": "https://wpnews.pro/news/show-hn-marginal-see-which-customers-and-features-drive-your-ai-api-costs.jsonld"}}