LiteLLM integration does not report cached, reasoning, or cache-write token usage
@alexander-alderman-webb đang làm issue này rồi.
Từ ngày 23/2/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 2.2k
- Fork
- 672
- Merge trung bình
- 22 giờ 47 phút
- Pull request đã merge (30 ngày)
- 224
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của getsentry/sentry-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
getsentry/sentry-python#7543 · 2 bình luận · 1 người được giao ·
-
Python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
getsentry/sentry-python#6992 · 1 bình luận ·
-
Improvement Python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
getsentry/sentry-python#6970 · 1 bình luận ·
-
Bug Python
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
getsentry/sentry-python#6504 · 1 bình luận ·
-
Improvement Python Spans
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
getsentry/sentry-python#5833 · 1 bình luận ·
Tất cả issue của getsentry/sentry-python
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
learningequality/ricecooker#747 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
run-llama/llama_index#23199 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
KhronosGroup/glTF-Blender-IO#2769 ·