Skip to content

Conversation

@viniciusdsmello
Copy link
Contributor

Pull Request

Summary

Adds a fallback mechanism to capture cost from LiteLLM response headers when response_cost is zero or unavailable.

Changes

  • Modified extract_litellm_metadata to track response headers and check for cost fallback
  • Added _extract_cost_from_headers helper function to parse x-litellm-response-cost and x-litellm-response-cost-original headers

Context

In some cases, the response_cost from LiteLLM's hidden params is returned as 0, but the actual cost is available in the response headers under x-litellm-response-cost. This fix ensures we capture cost data from headers as a fallback when the primary source fails.

Applies to both streaming and non-streaming completions.

Testing

  • Unit tests
  • Manual testing
  • Postman CI/CD
  • Other (please specify)

@gustavocidornelas gustavocidornelas merged commit 43a7d2e into main Dec 23, 2025
5 checks passed
@gustavocidornelas gustavocidornelas deleted the vini/open-8556-bug-litellm-tracer-isnt-capturing-the-cost branch December 23, 2025 13:46
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.

3 participants