Skip to content

Fix/langfuse cache cost 11.11#1

Open
liaoweiqiang-dao42 wants to merge 6 commits intomainfrom
fix/langfuse-cache-cost-11.11
Open

Fix/langfuse cache cost 11.11#1
liaoweiqiang-dao42 wants to merge 6 commits intomainfrom
fix/langfuse-cache-cost-11.11

Conversation

@liaoweiqiang-dao42
Copy link

Title

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test

Changes

Xeuva and others added 6 commits May 8, 2025 16:54
Support reading cached tokens from both legacy format (cache_read_input_tokens)
and OpenAI's new format (prompt_tokens_details.cached_tokens).

This fixes the issue where Langfuse was not calculating prompt cache discounts
because litellm proxy returns cached_tokens in prompt_tokens_details, but the
langfuse integration only looked for cache_read_input_tokens at the top level.

Changes:
- Read cache_read_input_tokens from both top-level and prompt_tokens_details.cached_tokens
- Read cache_creation_input_tokens from both top-level and prompt_tokens_details.cache_creation_tokens
- Update usage dict to use pre-calculated values instead of getattr

Fixes: Langfuse not applying cache discount for OpenRouter/OpenAI models
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants