Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

LLM Cost Engineering

Free · sign in to start and track progress

1 · Spending less on the same work

  • 1Token economics of an agent fleet
  • 2Prompt caching as system design
  • 3Trimming and compacting context
  • 4Batch, flex and fast tiers

2 · Changing the model, and governing the spend

  • 5Cost-quality curves, routing and cascades
  • 6Distilling into small models
  • 7Self-hosting break-even
  • 8Attribution, budgets and alerts

    Exercise answers

    • Answer: Build a cost ledger with budgets and alerts
CapstoneCost-engineer an agent pipelineReference implementation

Module 2 · Changing the model, and governing the spend · Lesson 8

Attribution, budgets and alerts

Attributing every token to a customer, case, agent and step through a gateway, an observability tool and your own ledger, allocating shared costs, reconciling with the invoice, and enforcing a hierarchy of budgets with alerts that catch runaway spend.

70 min 1 video 2 exercises 6-question quiz Answers
Setup for the exercises:Install Claude CodePython with uv

By the end of this lesson you can

  • Design an attribution scheme (customer, case, case type, agent, step, prompt version, model) and propagate it to a gateway, an observability tool and a cost ledger
  • Allocate shared costs such as evals, cache writes and backfills with an explicit rule, and compute cost per completed case by customer
  • Reconcile a usage ledger with the provider invoice and explain the usual gaps
  • Set budgets at organisation, customer, case and run level, and choose alerts that detect anomalies without paging on noise

On this page

  • Intuition: time recording
  • The attribution scheme
  • Getting usage right
  • Allocating shared costs
  • Worked example: a month by firm
  • Reconciliation
  • Budgets and alerts
  • Alerts that mean something
  • Misconceptions and limits
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01Intuition: time recording
  2. 02The attribution scheme
  3. 03Allocating shared costs
  4. 04Budgets and alerts
  5. 05Misconceptions and limits
  6. 06Connections
  7. 07Summary

Sources & further reading

  • Who Pays for the KV Cache? Attributing Shared AI Inference Spend Across Kubernetes and LLM Provider BillsPaper · Urista · 2026A recent single-author preprint with open-source tooling. Read it for the failure modes at the seams between gateway logs, provider bills and GPU allocations, and for the result that a token meter and a time-share meter can disagree by 12–14 points for one tenant on a shared vLLM server.
  • AI Gateway Custom Reporting API (Vercel docs)Docs · VercelAttaching user and tags to requests (body or headers, up to 10 tags), querying spend grouped by user, tag, model, provider or API key, the response's cost fields, and the per-write and per-query prices of reporting itself.
  • AI Gateway budgets and spend limits (Vercel docs)Docs · VercelStacked team, project, API key and user budgets, default budgets, soft-cap semantics, 402 rejections, and spend alerts at 50, 75 and 100% of a limit.
  • Custom properties (Helicone docs)Docs · HeliconeHelicone-Property-* headers and the reserved Helicone-User-Id for segmenting cost by user, conversation or feature, and alerts on property values.
  • Token and cost tracking (Langfuse docs)Docs · LangfuseIngested versus inferred cost, usage types as exclusive buckets (cache reads counted once), model definitions with pricing tiers, and querying cost by user and tag.
  • Alerts (Langfuse docs)Docs · LangfuseThreshold alerts on aggregated metrics such as p95 cost or latency over a window, filtered by model, tag or user, routed to Slack, webhooks or GitHub Actions.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 7 more sections
  • 2 hands-on exercises
  • A 6-question quiz
  • Progress, quiz scores and bookmarks