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
What it makes
Real output from this kit
- Sample file601 bytes, download to openMarginFrom the kit's tests
- Sample file3 KB, download to openMarginFrom the kit's tests
- Sample file1 KB, download to openMarginFrom the kit's tests
How this works
- It is a skill: written instructions Claude reads when your request matches what the skill is for. You do not call it by name; just ask for the task.
- While it works, it reads and changes files in the places it lists, nowhere else.
- It runs these commands on your computer: node scripts/margin.mjs.
- Nothing runs until you choose to use it, and you can remove it any time.
SKILL.md
Gross margin by customer
AI products have a cost of goods that moves with usage, so two customers on the same plan can have very different margins. This kit puts revenue, model costs, and the rest of cost of revenue side by side per customer and month, so pricing conversations start from facts.
Inputs
- Usage in the shared schema (
timestamp, customer, task, model, tokens..., cost_usd). From app logs, or from provider exports via thellm-usage-normalizerkit. Blankcost_usdis priced with--prices(check those prices against each provider's current pricing first). - Revenue
data/revenue.csv:customer,month,revenue. Use recognized monthly revenue (an annual contract is 1/12 per month), net of discounts. Customer names must match the usage file exactly. - Other cost of revenue (optional)
data/cogs.csv:item,month,amount,allocation. Allocation isusage(by LLM cost share, good for hosting and vector databases),revenue(payment fees),even(per-customer tools), orcustomer:<name>(dedicated infrastructure). Only cost of revenue belongs here, not sales or R&D. - Target margin (default 70%,
--target 0.7). Ask the user; 60 to 80% is common for software with AI features.
Steps
- Check that customer names match between usage and revenue. List names that appear in only one file and fix them with the user (usually a naming mismatch or an unmapped API key).
Run:
node scripts/margin.mjs data/usage.csv --revenue data/revenue.csv --cogs data/cogs.csv --prices data/llm-prices.csv --target 0.7 --out out/margin- Read
out/margin.mdand report per month: overall gross margin, each negative customer, each below-target customer, and the task that drives their cost. Explain the levers for each problem customer, in this order:
- Cost: cheaper model for that task's simpler steps, better prompt caching, fewer retries (a low success rate burns money).
- Packaging: usage caps or overage on the heavy task (see
consumption-guardrails). - Price:
price_for_targetis what they would need to pay to hit the target. Useusage-pricing-simulatorto test a new model on everyone before changing one deal.
- Mention unattributed LLM cost (internal use, evals, trials). It is real cost even though it is not in any customer's margin.
Output template
**October gross margin: 57% (target 70%).**
- cobalt-labs: -116% ($60 revenue, $130 cost). 96% of cost is research_agent. Needs $433/mo for 70%.
- northwind-co: 40%. research_agent again. Needs $477/mo.
- Everyone else is above 80%.
Biggest lever: research_agent cost per run. Next: model choice for its steps, then usage-based pricing for it.Guardrails
- Margins use the price table you give it. Say "based on the example prices" if the user has not checked them.
- Revenue and margins per customer are sensitive. Keep them in
out/and do not paste the full table into shared channels. - This kit does not change prices or contracts. It informs a decision people make.
README.md
Gross margin by customer
Shows the gross margin of every customer of your AI product: revenue minus model costs minus allocated hosting and other cost of revenue. It flags who is negative or under target, which task drives their cost, and what they would need to pay to hit your target.
Who it is for: founders and finance leads at AI products preparing pricing changes, renewals, or board reviews.
Example
Input: examples/usage.csv (October LLM usage), examples/revenue.csv, examples/cogs.csv (hosting, vector database, support tooling, dedicated storage), examples/prices.csv.
Output (out/margin.md):
| Customer | Revenue | LLM cost | Other COGS | Gross margin | Status | Biggest cost | Price for 70% |
|---|---|---|---|---|---|---|---|
| cobalt-labs | $60 | $66.22 | $63.53 | -116.3% | negative | research_agent (96%) | $433 |
| northwind-co | $240 | $73.26 | $69.75 | 40.4% | below target | research_agent (94%) | $477 |
| bluepeak | $149 | $3.30 | $7.92 | 92.5% | ok | code_review (99%) | $37 |
What it can access
- Runs
node scripts/margin.mjs(Node built-ins only). - Reads
data/. Writesout/margin*. - No network.
Setup
None. If your usage comes from provider exports, run @agentcosts/llm-usage-normalizer first. Check the example prices against each provider's current pricing before trusting the numbers.
Files
- README.md
- SKILL.md
- examples/cogs.csv
- examples/prices.csv
- examples/revenue.csv
- examples/usage.csv
- kit.json
- scripts/lib.mjs
- scripts/margin.mjs
- scripts/usage.mjs
Did it work?
0worked for them0did not work
Sign in to say whether it worked for you.
Nobody has said yet. Tried it? Tell the next person.
