Docs/Aigovernance/Aicost

AI Cost (FinOps)

Control and optimize your AI spending with comprehensive Cost (FinOps) capabilities. Cost is the primary indicator and measurable outcome of FinOps - providing visibility, allocation, optimization, and accountability for your AI investments.

What is AI Cost (FinOps)?

Cost (FinOps) for AI helps organizations achieve cost visibility, allocation, optimization, and accountability:

  • Track every dollar spent on AI operations
  • Attribute costs to customers, teams, or products
  • Optimize spending through data-driven decisions
  • Forecast future costs and budget accordingly
  • Maximize ROI on AI investments

Key Capabilities

1. Real-Time Cost Tracking

See costs as they happen:

typescript
// View current spending const costs = await ants.finops.getCurrentCosts() console.log(`Today: $${costs.today}`) console.log(`This month: $${costs.month}`) console.log(`Rate: $${costs.hourlyRate}/hour`)

2. Cost Attribution

Know who's driving costs:

python
# Cost by customer customer_costs = ants.finops.get_costs( group_by='customer_id', period='last_30_days' ) for customer in customer_costs: print(f"{customer.name}: ${customer.cost}") print(f" Queries: {customer.query_count}") print(f" Avg cost/query: ${customer.avg_cost}")

3. Budget Management

Set limits and get alerts:

typescript
await ants.finops.createBudget({ name: 'Q4 AI Budget', amount: 10000, period: 'quarterly', alerts: [ { at: 7000, notify: ['slack', 'email'] }, { at: 9000, notify: ['slack', 'email', 'pagerduty'] } ] })

4. ROI Analytics

Measure business impact:

python
roi = ants.finops.calculate_roi( costs=5000, revenue=25000, period='month' ) print(f"ROI: {roi.percentage}%") print(f"Payback period: {roi.payback_days} days") print(f"Cost per conversion: ${roi.cost_per_conversion}")

Cost Breakdown

What Drives Costs?

Cost Per Operation

typescript
// Detailed cost breakdown const breakdown = await ants.finops.getCostBreakdown({ agent: 'customer-support', period: 'last_7_days' }) console.log('Cost per operation:') console.log(` Classification: $${breakdown.classification}`) console.log(` Retrieval: $${breakdown.retrieval}`) console.log(` Generation: $${breakdown.generation}`) console.log(` Total: $${breakdown.total}`)

Optimization Strategies

1. Model Selection

Use the right model for the job:

python
# Expensive gpt4_cost = ants.finops.estimate_cost( model='gpt-4', tokens=1000 ) # $0.03 # More economical gpt35_cost = ants.finops.estimate_cost( model='gpt-3.5-turbo', tokens=1000 ) # $0.002 # Savings: 93%

2. Response Caching

Eliminate redundant calls:

typescript
// Without caching const cost1 = await processQuery("What is AI?") // $0.03 const cost2 = await processQuery("What is AI?") // $0.03 again! // With caching ants.cache.enable() const cost1 = await processQuery("What is AI?") // $0.03 const cost2 = await processQuery("What is AI?") // $0.00 (cached) // Savings: 50% for repeated queries

3. Prompt Optimization

Shorter prompts = lower costs:

python
# Long prompt (inefficient) prompt = f""" You are a helpful assistant. Please help the user. Context: {context} # 5000 tokens User question: {question} Please provide a detailed answer. """ # Cost: $0.15 # Optimized prompt prompt = f"Context: {summarize(context)}\\nQ: {question}" # 500 tokens # Cost: $0.015 # Savings: 90%

4. Smart Sampling

Don't track everything:

typescript
// Sample strategically const shouldTrace = (request) => { // Always track errors if (request.error) return true // Always track premium users if (request.userTier === 'enterprise') return true // Sample 10% of free tier return Math.random() < 0.1 }

Cost Dashboards

Real-Time View

typescript
// Get cost trends const trends = await ants.finops.getTrends({ period: 'last_90_days', granularity: 'daily' }) trends.forEach(day => { console.log(`${day.date}: $${day.cost}`) })

Alerting

Budget Alerts

python
# Set up alerts ants.finops.create_alert({ 'name': 'Monthly budget warning', 'type': 'budget', 'threshold': 0.8, # 80% of budget 'channels': ['email', 'slack'] }) ants.finops.create_alert({ 'name': 'Anomaly detection', 'type': 'anomaly', 'sensitivity': 'high', 'channels': ['slack', 'pagerduty'] })

Cost Spike Detection

typescript
// Automatic anomaly detection ants.finops.enableAnomalyDetection({ baseline: 'last_7_days', threshold: 2.0, // 2x normal minSpend: 100 // Only alert if > $100 })

Reporting

Monthly Reports

python
# Generate cost report report = ants.finops.generate_report( period='october_2025', include=['costs', 'trends', 'recommendations'] ) # Export to PDF report.export('october_2025_costs.pdf') # Email to team report.email(['finance@company.com'])

Custom Reports

typescript
const report = await ants.finops.createCustomReport({ name: 'Executive Summary', sections: [ 'total_costs', 'cost_by_team', 'roi_metrics', 'optimization_opportunities' ], format: 'pdf', schedule: 'monthly' })

Best Practices

1. Tag Everything

python
trace = ants.trace.create( name='query', metadata={ 'customer_id': 'cust_123', 'team': 'sales', 'product': 'chatbot', 'environment': 'production' } )

2. Set Budgets

typescript
// Team budgets await ants.finops.createBudget({ team: 'engineering', amount: 5000, period: 'monthly' })

3. Review Weekly

python
# Weekly review weekly = ants.finops.get_weekly_summary() print(f"This week: ${weekly.current}") print(f"Last week: ${weekly.previous}") print(f"Change: {weekly.percent_change}%")

4. Optimize Continuously

typescript
// Get recommendations const recs = await ants.finops.getOptimizations() recs.forEach(rec => { console.log(`${rec.title}: Save $${rec.savings}/month`) console.log(`Action: ${rec.action}`) })

Integration with Billing

Connect to Stripe

python
# Sync costs to Stripe ants.finops.configure_billing({ 'provider': 'stripe', 'api_key': os.getenv('STRIPE_API_KEY'), 'pass_through': True, # Bill customers directly 'markup': 1.2 # 20% markup })

Usage-Based Pricing

typescript
// Charge customers based on AI usage await ants.finops.enableUsageBilling({ pricePerToken: 0.00001, minimumCharge: 5.00, billingCycle: 'monthly' })

Next Steps

Set Up Cost Tracking →

© 2026 ANTS Platform, Inc.Docs v1.0 · Last updated June 2026