Gross margin by customer
@agentcosts/gross-margin-by-customer
Gross margin per customer for an AI product: revenue minus LLM cost minus allocated hosting and other cost of revenue. Flags negative and below-target customers, names the task driving their cost, and gives the price each one would need to hit your target margin.
- Activity
- New: be the first to try it
- Installs
- 0 installs
- Likes
- 0 likes
- Clones
- 0 clones
- 1{
- 2 "name": "gross-margin-by-customer",
- 3 "owner": "agentcosts",
- 4 "version": "1.0.0",
- 5 "type": "skill",
- 6 "description": "Gross margin per customer for an AI product: revenue minus LLM cost minus allocated hosting and other cost of revenue. Flags negative and below-target customers, names the task driving their cost, and gives the price each one would need to hit your target margin.",
- 7 "category": "finance",
- 8 "license": "MIT",
- 9 "compat": ["claude-code"],
- 10 "permissions": {
- 11 "shell": ["node scripts/margin.mjs"],
- 12 "files": { "read": ["./data/**"], "write": ["./out/margin*"] }
- 13 },
- 14 "tests": {
- 15 "cases": [
- 16 {
- 17 "name": "computes margins with allocated costs for the example month",
- 18 "inputs": {},
- 19 "checks": [
- 20 { "type": "command_exits_zero", "command": "node scripts/margin.mjs examples/usage.csv --revenue examples/revenue.csv --prices examples/prices.csv --cogs examples/cogs.csv --out out/margin" },
- 21 { "type": "file_contains", "path": "out/margin.md", "text": "| cobalt-labs | $60 | $66.22 | $63.53 | -116.3% | **negative** |" },
- 22 {
- 23 "type": "output_matches_schema",
- 24 "path": "out/margin.json",
- 25 "schema": {
- 26 "type": "object",
- 27 "required": ["totals", "customers"],
- 28 "properties": {
- 29 "totals": {
- 30 "type": "array",
- 31 "minItems": 1,
- 32 "maxItems": 1,
- 33 "items": {
- 34 "type": "object",
- 35 "properties": {
- 36 "month": { "const": "2026-10" },
- 37 "revenue": { "const": 746 },
- 38 "gross_margin": { "const": 0.5723 },
- 39 "cost_of_revenue": { "const": 319.09 },
- 40 "negative": { "const": ["cobalt-labs"] },
- 41 "below_target": { "const": ["northwind-co"] }
- 42 }
- 43 }
- 44 },
- 45 "customers": { "type": "array", "minItems": 6, "maxItems": 6 }
- 46 }
- 47 }
- 48 }
- 49 ]
- 50 },
- 51 {
- 52 "name": "allocates costs by usage, evenly, and to one customer",
- 53 "inputs": {
- 54 "data/usage.csv": "timestamp,customer,task,model,cost_usd\n2026-09-03T10:00:00Z,a,t,m,30\n2026-09-04T10:00:00Z,b,t,m,10\n2026-09-05T10:00:00Z,internal,evals,m,5\n",
- 55 "data/revenue.csv": "customer,month,revenue\na,2026-09,100\nb,2026-09,100\n",
- 56 "data/cogs.csv": "item,month,amount,allocation\nhosting,2026-09,40,usage\ntools,2026-09,20,even\nstorage,2026-09,10,customer:b\n"
- 57 },
- 58 "checks": [
- 59 { "type": "command_exits_zero", "command": "node scripts/margin.mjs data/usage.csv --revenue data/revenue.csv --cogs data/cogs.csv --target 0.6 --out out/margin" },
- 60 {
- 61 "type": "output_matches_schema",
- 62 "path": "out/margin.json",
- 63 "schema": {
- 64 "type": "object",
- 65 "properties": {
- 66 "totals": {
- 67 "type": "array",
- 68 "items": { "type": "object", "properties": { "revenue": { "const": 200 }, "cost_of_revenue": { "const": 110 }, "unattributed_llm_cost": { "const": 5 }, "below_target": { "const": ["a"] } } }
- 69 }
- 70 }
- 71 }
- 72 }
- 73 ]
- 74 }
- 75 ]
- 76 }
- 77}
