본문으로 건너뛰기
Skillpedia
분석 및 스프레드시트41k · #6831

exploring-llm-costs

하는 일

이 스킬은 PostHog가 각 모델 호출마다 기록하는 비용 데이터를 바탕으로 AI 모델 사용 비용에 대한 질문에 답합니다. AI 예산을 관리하거나 어떤 모델이나 기능이 가장 비싼지 알고 싶은 사람을 위한 것입니다.

사용하는 경우

  • ✓팀이 AI 모델에 시간에 따라 얼마를 쓰는지 알고 싶을 때.
  • ✓비용이 급증해서 어떤 모델, 사용자, 기능이 원인인지 찾아야 할 때.
  • ✓AI 지출을 계속 보기 위해 비용 차트나 알림이 필요할 때.

스킬 링크

https://github.com/PostHog/posthog/blob/master/products/ai_observability/skills/exploring-llm-costs/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/PostHog/posthog/blob/master/products/ai_observability/skills/exploring-llm-costs/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“지난달 AI 모델에 얼마를 썼고, 어떤 모델이 가장 비쌌나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

PostHog에서 각 AI 모델 호출의 비용을 합산하고, 선택한 기준(모델, 제공자, 사용자, 사용자 지정 속성 등)으로 묶습니다. 기간을 비교해 급증을 설명할 수 있고, 결과를 차트나 대시보드 항목으로 저장할 수 있습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Exploring LLM costs

PostHog attaches per-call cost metadata to every $ai_generation and $ai_embedding event at ingestion time. Every cost question reduces to an aggregation over those two event types — the interesting variation is only in how you group, filter, and compare.

This skill covers the common cost investigations: total spend, breakdowns (model, provider, user, trace, custom property), token and cache-hit analysis, regression debugging, and materializing results as insights, dashboards, or alerts.

Tools

Tool Purpose
posthog:query-trends Native cost trends with supported sums, breakdowns, and comparisons
posthog:execute-sql Ad-hoc HogQL for any cost aggregation — the workhorse of this skill
posthog:query-llm-traces-list List traces with rolled-up cost, token, and error metrics
posthog:query-llm-trace Cost breakdown of a single trace across all its events
posthog:read-data-schema Discover which custom properties exist for breakdowns
posthog:insight-create Materialize a cost chart as a saved insight
posthog:dashboard-create Bundle cost insights into a dashboard
posthog:alert-create Alert when cost crosses a threshold
posthog:generate-app-url Build region- and project-qualified links back to the UI

Core rules

Three rules cover most of what goes wrong:

  • Sum $ai_total_cost_usd for rollups, never the components. Components drop request and web-search fees. The UI's cost cells sum $ai_total_cost_usd over event IN ('$ai_generation', '$ai_embedding'); mirror that. Full schema and rationale in cost properties.
  • Always include both $ai_generation and $ai_embedding in cost queries unless the project demonstrably does not use embeddings — missing them silently under-counts. $ai_trace and $ai_span carry no rollup cost; some SDK wrappers duplicate $ai_total_cost_usd onto $ai_trace so don't include it in rollups or you'll double-count.
  • Always set a time range. Cost queries without one scan the full events table.

$ai_total_cost_usd is set at ingestion via one of three paths (passthrough, custom pricing, automatic lookup). When a cost looks wrong, read $ai_cost_model_source first — see cost sources for the precedence rules and a diagnostic query.

Cache-hit math depends on whether the provider reports cache tokens inclusively or exclusively of $ai_input_tokens. Always branch on the per-event $ai_cache_reporting_exclusive flag, never on provider name — see cache accounting for the exclusive-vs-inclusive formula.

distinct_id is the canonical user dimension. Customers often attach custom properties (feature, tenant_id, workflow_name) — discover them with posthog:read-data-schema before grouping. Don't guess names.

Workflow: total spend in a window

posthog:execute-sql
SELECT round(sum(toFloat(properties.$ai_total_cost_usd)), 4) AS total_cost_usd
FROM events
WHERE event IN ('$ai_generation', '$ai_embedding')
    AND timestamp >= now() - INTERVAL 30 DAY

Workflow: cost breakdowns

Every cost question is a variation of the same template — group by a dimension, aggregate $ai_total_cost_usd. See breakdown patterns for ready-to-run recipes:

  • Cost over time (daily)
  • Cost by model
  • Cost by user (top spenders)
  • Cost by trace (top expensive traces)
  • Cost by custom dimension
  • Cost-per-call distribution
  • Input vs output vs cache economics

Workflow: inspect a single trace's cost

When the user pastes a trace URL and asks about its cost, fetch the trace and surface the per-event breakdown:

posthog:query-llm-trace
{ "traceId": "<trace_id>", "dateRange": {"date_from": "-30d"} }

Sum $ai_total_cost_usd across the returned events, grouped by span name or model, to show which step(s) drove the cost. The trace response already includes totalCost as a convenience.

Workflow: debug a cost regression

"Our LLM bill jumped — w

자주 묻는 질문

비용 수치는 어디서 오나요?

PostHog는 기록될 때 각 AI 호출에 비용 정보를 붙이므로, 합계는 그 데이터에서 나옵니다.

토큰 사용량도 보여 줄 수 있나요?

네. 비용과 함께 토큰과 캐시 히트도 확인할 수 있습니다.

대시보드에 올릴 수 있나요?

네. 비용 차트를 인사이트로 저장하고 대시보드에 추가할 수 있습니다.

상세 정보

작성자의 원본 설명

Investigate LLM spend in PostHog — total cost over time, cost by model, provider, user, trace, or custom dimension, token and cache-hit economics, and cost regressions. Use when the user asks "how much are we spending on LLMs?", "which model / user / feature is most expensive?", "why did cost spike?", wants to build a cost dashboard or alert, or pastes a trace URL and asks about its cost.

repo: PostHog/posthog

인기도

GitHub 스타
41k
순위
#6831
라이선스
—
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬