2 / 10
Как считать и отслеживать cost / tokens в production: per-user, per-feature attribution, budgets, alerts?
Production cost tracking — не pre-flight tiktoken-подсчёт (это разные задачи), а attribution + aggregation + alerts. Каждый LLM call помечается метаданными: userId, feature, route, model, prompt_version → агрегация в Langfuse Dashboards / LangSmith Metrics / Helicone analytics / custom Postgres ledger. Cost = tokens × pricing-table per-model (gpt-4o-mini $0.15/$0.60, gpt-4o $2.50/$10, claude-3-7-sonnet $3/$15 за 1M input/output — даты на 2025). Budget alerts: Slack webhook когда daily spend > threshold; hard limit = return 429 если daily/user limit hit. Critical: split by model чтобы видеть cost-down opportunities.