Skip to main content

토큰 추적

LLM 호출의 토큰 사용량 및 비용을 추적합니다.

개요

토큰 추적 시스템은 LLM별 토큰 사용량을 추적하고 비용을 추정합니다. 세션/일일/월별 임계치를 설정하여 비용을 관리할 수 있습니다.

설정

.claude/config/default.json:

{
"multi_llm": {
"token_tracking": {
"enabled": true,
"use_json_output": true,
"fallback_to_estimation": true,
"estimation_method": "char_ratio"
},
"cost_alerts": {
"enabled": true,
"thresholds": {
"session_usd": 0.50,
"daily_usd": 5.00,
"monthly_usd": 50.00
},
"actions": {
"log": true,
"notify_user": true
}
}
}
}

토큰 카운팅 방식

  1. JSON 출력 우선: LLM 응답의 JSON에서 실제 토큰 정보 추출
  2. Fallback 추정: JSON 파싱 실패 시 문자 수 기반 추정

토큰 추정 비율

언어추정 비율
한글 많음 (50%+)약 2자/토큰
혼합 (20-50%)약 3자/토큰
영어 많음약 4자/토큰

LLM별 비용

LLM모델Input (1K)Output (1K)
ClaudeSonnet 4.5$0.003$0.015
ClaudeHaiku$0.00025$0.00125
OpenCodeGLM-4.7$0.0001$0.0002
GeminiGemini-2.5-Pro$0.00125$0.00375
KiloClaude Sonnet 4.5$0.003$0.015

비용 알림

임계치 초과 시 알림을 표시합니다.

⚠️ **비용 알림**: 세션 비용 $0.52 (임계치: $0.50 초과)

알림 설정

임계치기본값설명
session_usd$0.50세션당 비용
daily_usd$5.00일일 비용
monthly_usd$50.00월간 비용

사용량 명령어

# 세션 사용량 요약
/usage

# Multi-LLM 성능 통계
/llm-stats

# 기간별 통계
/llm-stats week
/llm-stats month

데이터 마스킹

프롬프트/응답 내 민감 정보를 자동으로 마스킹합니다.

{
"data_masking": {
"enabled": true,
"patterns": {
"api_key": "[A-Za-z0-9_-]{32,}",
"password": "(?i)(password|passwd|pwd)...",
"email": "[a-zA-Z0-9._%+-]+@..."
}
}
}

마스킹 대상:

  • API 키, 토큰
  • 비밀번호, 시크릿
  • 이메일 주소
  • Private Key

로그 위치

파일내용
llm-performance.log성능 통계
llm-tokens/LLM별 토큰 사용량
cost-alerts.log비용 알림 기록

스마트 캐싱

동일한 프롬프트에 대한 반복 호출을 캐싱하여 비용을 절감합니다.

{
"cache": {
"enabled": true,
"directory": ".claude/custom/cache/llm",
"ttl_seconds": 3600,
"max_entries": 100,
"strategy": "lru",
"invalidation": {
"on_file_change": true,
"on_git_commit": true
}
}
}

다음 단계