Overview
LiteLLM automatically calculates and tracks costs for all supported LLM providers. Track spending across models, users, teams, and API keys to manage budgets and optimize usage.Automatic Cost Calculation
Costs are calculated automatically for every request:Supported Cost Metrics
LiteLLM tracks costs for:- Completion/Chat - Input and output tokens
- Embeddings - Per token or per request
- Image Generation - Per image, resolution, quality
- Audio (Speech) - Per character or per second
- Audio (Transcription) - Per second
- Fine-tuning - Training tokens
- Realtime API - Session duration, audio input/output
Provider Support
Cost tracking for 100+ providers:- OpenAI (GPT-4, GPT-3.5, etc.)
- Anthropic (Claude)
- Google (Gemini, Vertex AI)
- Azure OpenAI
- AWS Bedrock
- Cohere
- Replicate
- Together AI
- And many more…
Accessing Cost Information
Response Object
Streaming Responses
For streaming, cost is available in the final chunk:Custom Pricing
Override default pricing for custom deployments:Custom Pricing with Router
Budget Management
Set Budget Limits
Prevent overspending with budget limits:User-Level Budgets
Set budgets per user or API key:Cost Logging
Custom Cost Logger
Database Cost Tracking
Cost Analytics
Query Costs by Model
Query Costs by User
Time-Based Analysis
Cost Optimization
Model Cost Comparison
Prompt Optimization
Reduce costs by optimizing prompts:Choose Cost-Effective Models
Cost Alerting
Threshold-Based Alerts
Integration with Observability Platforms
Langfuse Integration
DataDog Integration
Best Practices
Cost Management Tips
- Monitor daily - Track costs in real-time
- Set budgets - Use budget limits to prevent overruns
- Optimize prompts - Reduce token usage
- Cache responses - Avoid redundant API calls
- Use cheaper models - Balance cost vs. quality
- Track by user - Identify high-cost users
- Alert on thresholds - Get notified of unusual spending
- Analyze trends - Review cost patterns weekly
Cost Calculation Details
Token-Based Pricing
Most models charge per token:Image Generation Pricing
Audio Pricing
Related Features
- Caching - Reduce costs with response caching
- Load Balancing - Optimize cost with routing
- Logging - Track all cost metrics
- Guardrails - Prevent expensive policy violations