LiteLLM integration does not report cached, reasoning, or cache-write token usage
維護者通常 1 天內回覆
評估
這個 Issue 還沒有評估資料。
描述
How do you use Sentry?
Sentry Saas (sentry.io)
Version
2.52.0
Steps to Reproduce
- Initialize Sentry with the LiteLLM integration and tracing enabled
- Make a completion call through LiteLLM to a provider that supports prompt caching (e.g., OpenAI, Anthropic, etc.)
- Inspect the resulting span data in Sentry's AI Agents dashboard
Expected Result
The span should include all available token usage detail attributes, just like the OpenAI and Anthropic integrations do:
gen_ai.usage.input_tokens(total input tokens)gen_ai.usage.input_tokens.cached(cached input tokens, subset of total)gen_ai.usage.input_tokens.cache_write(cache write tokens, if available)gen_ai.usage.output_tokens(total output tokens)gen_ai.usage.output_tokens.reasoning(reasoning tokens, subset of total)gen_ai.usage.total_tokens
This data is necessary for Sentry to correctly calculate model costs using the formula documented here:
input cost = (input_tokens - cached_tokens) x input_rate + cached_tokens x cached_rate
Without cached/reasoning token breakdown, all tokens are charged at the full standard rate, producing inaccurate cost estimates.
Actual Result
The LiteLLM integration's _success_callback only extracts three basic fields:
record_token_usage(
span,
input_tokens=getattr(usage, "prompt_tokens", None),
output_tokens=getattr(usage, "completion_tokens", None),
total_tokens=getattr(usage, "total_tokens", None),
)
The input_tokens_cached, input_tokens_cache_write, and output_tokens_reasoning parameters of record_token_usage() are never passed. Therefore, cost calculations in the AI Agents dashboard overestimate costs for cached-heavy workloads (all input tokens billed at the full rate) and misattribute output vs. reasoning token costs.
- 主要語言
- Python
- 星號
- 2.2k
- 分支
- 682
- 平均合併
- 1 天 8 小時
- 30 天內合併 PR
- 239
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
getsentry/sentry-python 的其他 Issue
-
Improvement Python Spans
難度 2/5 1-3 小時 新手友好度 78/100
getsentry/sentry-python#7876 · 2 則留言 ·
維護者通常 1 天內回覆
-
Bug Python
難度 2/5 1-3 小時 新手友好度 76/100
getsentry/sentry-python#7870 · 2 則留言 ·
維護者通常 1 天內回覆
-
Python
難度 2/5 1-3 小時 新手友好度 68/100
getsentry/sentry-python#6992 · 1 則留言 ·
維護者通常 1 天內回覆
-
Improvement Python
難度 2/5 1-3 小時 新手友好度 65/100
getsentry/sentry-python#6970 · 1 則留言 ·
維護者通常 1 天內回覆
-
match_regex_list raises IndexError when a pattern list contains an empty string可能已有人在做 @wahajahmed010 於 107 天前認領。 未關閉Bug Python
難度 2/5 1-3 小時 新手友好度 74/100
getsentry/sentry-python#6504 · 1 則留言 ·
維護者通常 1 天內回覆
查看 getsentry/sentry-python 的全部 Issue
相似的 Issue
-
docs pydanty:is-working
難度 2/5 1-3 小時 新手友好度 68/100
pydantic/pydantic-ai#10113 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 77/100
GreedyBear-Project/GreedyBear#1727 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
ARM-software/CMSIS-DSP#354 ·
-
難度 2/5 1-3 小時 新手友好度 68/100
kiat/codeAssist#391 ·
-
needs triage
難度 2/5 1-3 小時 新手友好度 83/100
darnitdevorg/darnit#587 ·
維護者通常 1 天內回覆