Skip to main content

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

  1. Monitor daily - Track costs in real-time
  2. Set budgets - Use budget limits to prevent overruns
  3. Optimize prompts - Reduce token usage
  4. Cache responses - Avoid redundant API calls
  5. Use cheaper models - Balance cost vs. quality
  6. Track by user - Identify high-cost users
  7. Alert on thresholds - Get notified of unusual spending
  8. Analyze trends - Review cost patterns weekly

Cost Calculation Details

Token-Based Pricing

Most models charge per token:

Image Generation Pricing

Audio Pricing