본문 바로가기
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

토큰 한 줄짜리 청구서가 아니야

호출에는 입력 토큰, 출력 토큰, 캐시 쓰기 토큰, 캐시 읽기 토큰, 서버 도구 호출, 이미지 토큰 비용이 각각 붙을 수 있어. 항목마다 단가가 다르므로 총 토큰 하나만 보면 무엇을 줄여야 할지 알 수 없어.

가장 큰 항목부터 찾아

긴 답을 주는 채팅은 출력 토큰이, 문서를 통째로 넣는 RAG 작업은 입력 토큰이 지배하기 쉬워. 반복 문맥을 잘 캐시하면 싼 캐시 읽기가 커지고 비싼 캐시 쓰기는 드물어야 해. 실제 청구에서 가장 큰 항목을 찾으면 다음 최적화의 방향이 보여.

기능 단위로 비용을 묶어

Anthropic Console은 조직 전체 비용을 보여 주지만 어떤 기능이 썼는지는 애플리케이션이 기록해야 해. cwkPippa는 호출마다 feature: 'chat' | 'heartbeat-weather' | 'council' 같은 표지를 남기고 JSONL에서 기능별 비용을 계산해. 가족 예산에서 설명할 수 있는 단위로 바꾸는 거야.

원칙: 가장 큰 비용 항목을 찾아 먼저 줄여. 눈에 띄지만 작은 항목을 다듬느라 시간을 쓰지 마.

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

기능별 비용 기록을 추가해 일주일 동안 모아. 비용 상위 세 기능을 찾고 하나를 고른 뒤, 바꾸기 전에 어떤 항목을 줄일지 적어.
Hint
측정 없는 비용 최적화는 미신이야. 먼저 가장 큰 줄을 찾아.

Progress

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

댓글 0

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

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