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

Claude 청구서 해부학

~14 min · cost, billing, tokens

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

매 invoice의 라인 여섯

Claude 청구서가 'tokens × price'보다 더 많은 라인 가져. 호출당 지불 — input 토큰, output 토큰, cache write 토큰(cache_control 썼으면), cache read 토큰(hit 났으면), tool invocation 토큰(서버 도구), 이미지 토큰(dimension에서 계산). 각 rate 다름; 라인 레벨 플래닝이 surprise 방지.

Dominant 라인 찾기

챗 워크로드면 output 토큰이 자주 dominate(긴 답). RAG-stuffing 워크로드면 input 토큰 dominate. 반복 컨텍스트 + caching이면 cache read dominate(싸고) cache write 드물어. 어느 라인 dominate하는지 알면 다음 절약 달러가 어디서 나올지 알아.

청구서당 X, 기능당 추적

Anthropic Console이 org-level 청구 보여. 어느 기능이 비용 driving하는지 알려면 매 호출에 feature 라벨 태그하고 직접 aggregate. cwkPippa는 호출당 feature: 'chat' | 'heartbeat-weather' | 'council' 로깅하고 JSONL에서 per-feature 비용 계산 — 청구서가 가족 예산 미팅에 explainable.

원칙: 청구서는 모양 가져. Dominant 라인 찾고, 그거 optimize, 나머지 무시.

Code

Per-call 비용 계산기·python
# Anthropic 가격 페이지의 rate (백만 토큰당 USD) — 배포 전 verify.
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 태깅과 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

프로젝트에 per-feature 비용 로깅 추가. 일주일 돌려. 비용 top 셋 기능 식별, optimize할 거 하나 픽. 바꾸기 전에 뭘 바꿀 의도인지 적어.
Hint
측정 없는 비용 최적화는 미신. 먼저 측정, 그다음 effort 어디 쓸지 선택.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.