C.W.K.
Stream
Lesson 01 of 06 · published

Anatomy of a Claude Bill

~14 min · cost, billing, tokens

Level 0Observer
0 XP0/64 lessons0/13 achievements
0/150 XP to next level150 XP to go0% complete

Six lines on every invoice

A Claude bill has more lines than 'tokens × price'. Per call you pay for: input tokens, output tokens, cache write tokens (if you used cache_control), cache read tokens (if you got a hit), tool invocation tokens (server tools), and image tokens (computed from dimensions). Each rate differs; planning at the line level prevents surprises.

Find the dominant line

For chat workloads, output tokens often dominate (long answers). For RAG-stuffing workloads, input tokens dominate. For repeated-context workloads with caching, cache reads dominate (cheap) and cache writes are rare. Knowing which line dominates tells you where the next dollar saved comes from.

Track per-feature, not per-bill

The Anthropic Console shows org-level billing. To know which feature drives cost, tag every call with a feature label and aggregate yourself. cwkPippa logs feature: 'chat' | 'heartbeat-weather' | 'council' per call and computes per-feature cost from JSONL — the bill is then explainable to the household budget meeting.

Principle: The bill has shape. Find the dominant line, optimize that, ignore the rest.

Code

Per-call cost calculator·python
# Rates from Anthropic pricing page (USD per million tokens) — verify before deploying.
RATES = {
    "claude-sonnet-4-6": {
        "input": 3.00,
        "output": 15.00,
        "cache_write": 3.75,
        "cache_read": 0.30,
    },
    "claude-haiku-4-5-20251001": {
        "input": 1.00,
        "output": 5.00,
        "cache_write": 1.25,
        "cache_read": 0.10,
    },
}

def cost(usage, model: str) -> float:
    r = RATES[model]
    return (
        (usage.input_tokens / 1_000_000) * r["input"]
        + (usage.output_tokens / 1_000_000) * r["output"]
        + (usage.cache_creation_input_tokens / 1_000_000) * r["cache_write"]
        + (usage.cache_read_input_tokens / 1_000_000) * r["cache_read"]
    )
Feature tagging and aggregation·python
import json, time

def log_call(feature: str, model: str, usage, log_path: str):
    line = {
        "ts": time.time(),
        "feature": feature,
        "model": model,
        "input": usage.input_tokens,
        "output": usage.output_tokens,
        "cache_write": usage.cache_creation_input_tokens,
        "cache_read": usage.cache_read_input_tokens,
        "cost_usd": cost(usage, model),
    }
    with open(log_path, "a") as f:
        f.write(json.dumps(line) + "\n")

External links

Exercise

Add per-feature cost logging to your project. Run for a week. Identify the top three features by cost and pick one to optimize. Write down what you intend to change before you change it.
Hint
Cost optimization without measurement is superstition. Measure first, then choose where to spend effort.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.