Spend Attribution

Which of my customers are unprofitable because of AI costs?

Customer Margin puts what each of your customers costs in AI calls next to what they pay you, from Stripe or your own figures, with alerts when a customer's margin drops and budgets that cap one customer's spend.

In the app: Customer Margin · Growth plan and aboveOpen in app →No account? Start free

With AI features, one heavy customer can cost more than they pay you while the average looks fine. Customer Margin shows the cost of each of your customers next to their revenue, so you can see who is unprofitable and cap them.

1. Tag calls with your customer

client.chat.completions.create(
    model="gpt-4o-mini", messages=messages,
    extra_headers={"X-Cost-Customer": account.slug},   # e.g. "acme-corp"
)

The Python wrapper takes tag_customer. The value also appears as customer in the FOCUS export's Tags column.

2. Add revenue

Stripe. On Customer Margin, paste a Stripe restricted key with read access to Invoices and Customers, and choose how a Stripe customer maps to your X-Cost-Customer value:

Match byUse when
Customer metadata key (default cognocient_customer)You store your account id on the Stripe customer
Stripe customer idYou send the Stripe id (cus_…) as X-Cost-Customer
Customer emailYou send the billing email as X-Cost-Customer

Paid invoices created in the month are summed per customer. Cognocient AI reads this month and last month on connect and then daily. Only USD invoices are counted; invoices in other currencies are listed as skipped, never converted. Invoices whose customer can't be matched are reported as unmatched revenue.

By hand. Enter a customer and amount for the month, or upload a CSV with columns end_customer, month, revenue_usd (month as YYYY-MM). A manual figure replaces Stripe's for that customer and month, so a correction never double counts.

3. Read the page

Each customer shows AI cost, revenue, margin after AI cost ((revenue − AI cost) ÷ revenue), AI cost as a share of revenue, and calls, lowest margin first. Customers with AI cost but no revenue (free users, trials) show "no revenue". Untagged AI cost is shown separately so you can see how much is not yet attributed.

4. Alerts and limits

  • Margin alert. Set a minimum margin (for example 60%). Once a day, any paying customer below it triggers one Slack / email alert for the month.
  • Customer budget. On Budgets, create a budget with scope Customer and the X-Cost-Customer value. Alert, Degrade (switch that customer to a cheaper model) or Block, like any budget.

The Stripe connection follows Stripe's documented Invoices API and has not yet been run against a live customer account.

On this page