Skip to content
SlashClone

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.

SkillFinancev1.0.0 (latest)Tested
Activity
New: be the first to try it
  1. 1{
  2. 2 "name": "gross-margin-by-customer",
  3. 3 "owner": "agentcosts",
  4. 4 "version": "1.0.0",
  5. 5 "type": "skill",
  6. 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. 7 "category": "finance",
  8. 8 "license": "MIT",
  9. 9 "compat": ["claude-code"],
  10. 10 "permissions": {
  11. 11 "shell": ["node scripts/margin.mjs"],
  12. 12 "files": { "read": ["./data/**"], "write": ["./out/margin*"] }
  13. 13 },
  14. 14 "tests": {
  15. 15 "cases": [
  16. 16 {
  17. 17 "name": "computes margins with allocated costs for the example month",
  18. 18 "inputs": {},
  19. 19 "checks": [
  20. 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. 21 { "type": "file_contains", "path": "out/margin.md", "text": "| cobalt-labs | $60 | $66.22 | $63.53 | -116.3% | **negative** |" },
  22. 22 {
  23. 23 "type": "output_matches_schema",
  24. 24 "path": "out/margin.json",
  25. 25 "schema": {
  26. 26 "type": "object",
  27. 27 "required": ["totals", "customers"],
  28. 28 "properties": {
  29. 29 "totals": {
  30. 30 "type": "array",
  31. 31 "minItems": 1,
  32. 32 "maxItems": 1,
  33. 33 "items": {
  34. 34 "type": "object",
  35. 35 "properties": {
  36. 36 "month": { "const": "2026-10" },
  37. 37 "revenue": { "const": 746 },
  38. 38 "gross_margin": { "const": 0.5723 },
  39. 39 "cost_of_revenue": { "const": 319.09 },
  40. 40 "negative": { "const": ["cobalt-labs"] },
  41. 41 "below_target": { "const": ["northwind-co"] }
  42. 42 }
  43. 43 }
  44. 44 },
  45. 45 "customers": { "type": "array", "minItems": 6, "maxItems": 6 }
  46. 46 }
  47. 47 }
  48. 48 }
  49. 49 ]
  50. 50 },
  51. 51 {
  52. 52 "name": "allocates costs by usage, evenly, and to one customer",
  53. 53 "inputs": {
  54. 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. 55 "data/revenue.csv": "customer,month,revenue\na,2026-09,100\nb,2026-09,100\n",
  56. 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. 57 },
  58. 58 "checks": [
  59. 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. 60 {
  61. 61 "type": "output_matches_schema",
  62. 62 "path": "out/margin.json",
  63. 63 "schema": {
  64. 64 "type": "object",
  65. 65 "properties": {
  66. 66 "totals": {
  67. 67 "type": "array",
  68. 68 "items": { "type": "object", "properties": { "revenue": { "const": 200 }, "cost_of_revenue": { "const": 110 }, "unattributed_llm_cost": { "const": 5 }, "below_target": { "const": ["a"] } } }
  69. 69 }
  70. 70 }
  71. 71 }
  72. 72 }
  73. 73 ]
  74. 74 }
  75. 75 ]
  76. 76 }