Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

LiteLLM integration does not report cached, reasoning, or cache-write token usage

未关闭
#5,455 4 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@alexander-alderman-webb 已经在做这个了。

开始于 2026年2月23日。

评估

这个 Issue 还没有评估数据。

描述

Bug Python Spans
How do you use Sentry?

Sentry Saas (sentry.io)

Version

2.52.0

Steps to Reproduce
  1. Initialize Sentry with the LiteLLM integration and tracing enabled
  2. Make a completion call through LiteLLM to a provider that supports prompt caching (e.g., OpenAI, Anthropic, etc.)
  3. 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
派生
672
平均合并
22 小时 47 分钟
30 天内合并 PR
224

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

getsentry/sentry-python 的其他 Issue

查看 getsentry/sentry-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。