4.9 KiB
4.9 KiB
Billing Dashboard Improvements
Summary of Changes
1. ✅ Migration Script - Add actual_provider_name Column
Status: Completed successfully
- Added
actual_provider_namecolumn toapi_usage_logstable - Migration script handles SQLite and MySQL/PostgreSQL
- Backfilled existing records with detected provider names
- Column now tracks real providers: WaveSpeed, Google, HuggingFace, etc.
2. ✅ Provider Breakdown in Monthly Budget Usage
Status: Completed
Changes Made:
- Updated
usage_tracking_service.pyto include all providers in breakdown:- Video (WaveSpeed, HuggingFace)
- Audio (WaveSpeed)
- Image (Stability, WaveSpeed)
- Image Edit (WaveSpeed)
- Search APIs (Tavily, Serper, Exa)
- Added provider breakdown display in
CompactBillingDashboard.tsx:- Shows top 5 providers by cost
- Displays as chips below the progress bar
- Format: "Provider: $X.XX"
- Updated
ProviderBreakdownTypeScript interface to include all providers
Location: frontend/src/components/billing/CompactBillingDashboard.tsx (lines ~1040-1063)
3. ✅ System Health Card Fix
Status: Fixed
Problem: System Health was showing zeros for all metrics (recent_requests, recent_errors, error_rate)
Solution: Updated get_lightweight_stats() in monitoring_middleware.py to:
- Query
APIRequesttable for last 5 minutes - Calculate real
recent_requestscount - Calculate real
recent_errorscount (status >= 400) - Calculate real
error_ratepercentage - Determine status based on error rate:
critical: error_rate > 10%warning: error_rate > 5%healthy: error_rate <= 5%
Location: backend/services/subscription/monitoring_middleware.py (lines 371-389)
4. ✅ API Error Handling for actual_provider_name
Status: Fixed
Problem: API was trying to access actual_provider_name column that didn't exist, causing errors
Solution:
- Added safe access using
getattr()with try/except - Falls back to enum value if column doesn't exist
- Migration script ensures column exists
Location: backend/api/subscription_api.py (lines 1247-1251)
5. ✅ Subscription API Review (Lines 611-1017)
Status: Reviewed and Fixed
Issues Found and Fixed:
- Missing limits in subscribe response: Added
video_calls,audio_calls,image_edit_calls,exa_callsto limits response - Provider breakdown calculation: Updated to include all providers, not just Gemini and HuggingFace
- Cost calculation: Updated to sum all provider costs, not just LLM providers
Code Quality:
- Error handling is comprehensive
- Logging is detailed and helpful
- Cache management is properly implemented
- Database transaction handling is correct
Files Modified
Backend
backend/models/subscription_models.py- Addedactual_provider_namefieldbackend/services/subscription/provider_detection.py- New utility for provider detectionbackend/services/subscription/usage_tracking_service.py- Enhanced provider breakdownbackend/services/subscription/monitoring_middleware.py- Fixed System Health statsbackend/services/llm_providers/main_video_generation.py- Added provider detectionbackend/services/llm_providers/main_image_generation.py- Added provider detectionbackend/services/llm_providers/main_audio_generation.py- Added provider detectionbackend/api/subscription_api.py- Fixed error handling, added missing limitsbackend/scripts/add_actual_provider_name_column.py- Migration script
Frontend
frontend/src/types/billing.ts- UpdatedProviderBreakdowninterfacefrontend/src/components/billing/CompactBillingDashboard.tsx- Added provider breakdown displayfrontend/src/components/billing/UsageLogsTable.tsx- Display actual provider namefrontend/src/components/monitoring/SystemHealthIndicator.tsx- Already correct (needsonRefreshprop)
Testing Checklist
- Migration script runs successfully
- Provider breakdown shows in Monthly Budget Usage
- System Health displays real data (not zeros)
- API Usage Logs show actual provider names
- Test with existing data (backfill)
- Test with new API calls (provider detection)
- Verify all providers appear in breakdown
Next Steps
- Monitor: Watch for any errors related to
actual_provider_namecolumn - Verify: Check that System Health shows real data after API calls
- Test: Verify provider breakdown appears correctly in compact view
- Enhance: Consider adding provider breakdown to detailed view as well
Notes
- The migration script successfully added the column and backfilled 0 records (no existing records to backfill)
- System Health now queries real data from
APIRequesttable - Provider breakdown includes all providers, sorted by cost (top 5 displayed)
- All changes are backward compatible (fallback to enum values if
actual_provider_nameis missing)