Budget Management
The Budget Management system provides sophisticated tracking and control over operational costs across all API services and data scraping operations.Architecture
Core Concepts
Budget Types
Service Types
Creating Budgets
Basic Budget Creation
lib/services/budget-manager.ts:99-149
Budget with Allocations
Create a budget with pre-allocated amounts for different services:Budget Validation
The system automatically validates that allocations don’t exceed the total budget:Tracking Costs
Manual Cost Allocation
lib/services/budget-manager.ts:276-327
Automatic Cost Tracking
Costs are automatically tracked when using the API Usage Tracker:Linking to External Systems
Link cost allocations to API usage or Apify runs:Budget Monitoring
Get Budget Summary
lib/services/budget-manager.ts:154-202
List All Budgets
lib/services/budget-manager.ts:237-271
Budget Alerts
Alerts are automatically created when spending reaches threshold percentages.Alert Thresholds
Configuring Alert Thresholds
lib/services/budget-manager.ts:206-232
Alert Checking
Alerts are automatically checked after each cost allocation:lib/services/budget-manager.ts:401-445
Budget Analytics
Global Analytics
Get comprehensive analytics across all budgets:lib/services/budget-manager.ts:332-396
Monthly Trend Analysis
Cost Optimization
Cost Optimization Recommendations
The system can generate optimization recommendations:Example Optimizations
Cost Forecasting
Database Schema
Budget Model
prisma/schema.prisma:538-566
BudgetAllocation Model
prisma/schema.prisma:568-588
CostAllocation Model
prisma/schema.prisma:590-612
Best Practices
1. Budget Hierarchy
Create a hierarchy of budgets:2. Regular Monitoring
Set up automated monitoring:3. Allocation Strategy
Allocate based on priority:FAQ: Budget Management
FAQ: Budget Management
Q: What happens when a budget is exceeded?A: The budget status changes to “EXCEEDED” and alerts are triggered. Cost allocations still work but generate warnings. You can pause operations by checking budget status before expensive operations.Q: Can I have overlapping budgets?A: Yes, you can have multiple active budgets for different purposes (e.g., project-specific budget + monthly operational budget). Each cost allocation is linked to one specific budget.Q: How accurate are cost forecasts?A: Forecast accuracy depends on historical data volume. With 30+ days of data, forecasts typically have 80-90% confidence. New platforms or seasonal variations may reduce accuracy.Q: Can I auto-pause services when budget is exhausted?A: Yes, implement budget checks before expensive operations:Q: How do I track costs for multiple projects?A: Create separate project budgets and include project metadata in cost allocations:Q: Can I get real-time spending notifications?A: Yes, set up webhooks or notification handlers when alerts are created. The system automatically creates alerts at configured thresholds.
Next Steps
- Configure API Monitoring to track usage in real-time
- Use the Discovery Pipeline cost-effectively
- Access budget reports via CLI Tools