Skip to content

Conversation

Sameerlite
Copy link
Collaborator

Title

Add Perplexity cost extraction from API response

Relevant issues

Fixes #15547

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

Bug FIx

Changes

This PR adds cost extraction functionality to Perplexity's chat transformation, allowing Perplexity to override LiteLLM's cost calculation by providing its own cost information in the API response.

I have updated perplexity provider to base_llm_http_handler and its own transformation methods. And I have used concept of over riding the cost as now perplexity provides cost in its response itself

This change ensures Perplexity users get accurate cost tracking that reflects the provider's actual pricing, improving cost transparency and accuracy for Perplexity API usage.

Screenshot 2025-10-15 at 1 36 39 PM

Change in perplexity API repsonse:

"usage": {
    "prompt_tokens": 5,
    "completion_tokens": 308,
    "total_tokens": 313,
    "search_context_size": "low",
    "cost": {
      "input_tokens_cost": 0,
      "output_tokens_cost": 0,
      "request_cost": 0.005,
      "total_cost": 0.005
    }
  }

Copy link

vercel bot commented Oct 20, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Oct 20, 2025 6:10pm

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@Sameerlite Sameerlite changed the title Litellm update perplexity cost tracking2 Update perplexity cost tracking Oct 20, 2025
@Sameerlite Sameerlite mentioned this pull request Oct 20, 2025
4 tasks
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.

1 participant