?
PPLX-24
feature
Created: 2025-12-21 Updated: 2025-12-21
Relationships Loading...
Attachments
Loading...
Comments (1)
triage-agent · 2025-12-21
# Feature Triage Report: PPLX-24 ## Feature Request Summary **Title:** Extract cost breakdown from Perplexity API usage.cost **Requested:** Update perplexity_client.py to extract cost breakdown from usage.cost if available: input_tokens_cost, output_tokens_cost, request_cost, total_cost. Include in metadata dict. ## Existing State Assessment **Status:** ALREADY EXISTS (Duplicate) **Current State:** This feature has been **fully implemented** in a previous session. The complete implementation exists across all layers of the application. ## Implementation Verification ### 1. Perplexity Client (backend/perplexity_client.py:185-193) ```python # Extract cost breakdown from model_extra['cost'] if available # Perplexity API returns cost data nested in model_extra dict if hasattr(chunk.usage, 'model_extra') and chunk.usage.model_extra: cost_data = chunk.usage.model_extra.get('cost', {}) if cost_data: usage['input_tokens_cost'] = cost_data.get('input_tokens_cost') usage['output_tokens_cost'] = cost_data.get('output_tokens_cost') usage['request_cost'] = cost_data.get('request_cost') usage['api_total_cost'] = cost_data.get('total_cost') ``` ### 2. Database Model (backend/models.py:240-244) ```python # Cost breakdown columns (from Perplexity API response) input_tokens_cost = Column(Float) output_tokens_cost = Column(Float) request_cost = Column(Float) api_total_cost = Column(Float) ``` ### 3. Pydantic Schema (backend/schemas.py:98-102) ```python # Cost breakdown from Perplexity API input_tokens_cost: Optional[float] = None output_tokens_cost: Optional[float] = None request_cost: Optional[float] = None api_total_cost: Optional[float] = None ``` ### 4. API Routes (backend/routers/queries.py:205-208) Cost breakdown fields are passed to the CRUD function and included in the "done" SSE event. ### 5. CRUD Operations (backend/crud.py:423-426, 454-457) `create_api_usage_log()` accepts and stores all four cost breakdown fields. ### 6. Database Migration Migration file exists: `a534488c3a48_add_cost_breakdown_columns.py` Adds columns: input_tokens_cost, output_tokens_cost, request_cost, api_total_cost ## Evidence of Working Implementation From logs, the implementation has been verified working: - Cost data is correctly extracted: `input_tokens_cost: 0.0, output_tokens_cost: 0.0, request_cost: 0.005, api_total_cost: 0.005` - Data is stored in the database - Data is included in API responses ## Recommendations **Action:** Cancel this issue as duplicate This feature was implemented as part of PPLX-23 work. The issue should be closed as the requested functionality is fully operational. ## Related Issues - PPLX-23: Original implementation of cost breakdown extraction (completed)