Docs
FinOps
Overview

FinOps - AI Cost Management

Control and optimize your AI spending with comprehensive FinOps capabilities.

What is AI FinOps?

FinOps (Financial Operations) for AI helps organizations:

  • 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:

// 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:

# 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:

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:

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?

AI Costs Breakdown:
├─ LLM API Calls (70%)
│  ├─ GPT-4: $5,250 (75%)
│  ├─ GPT-3.5: $1,050 (15%)
│  └─ Claude: $700 (10%)
├─ Embeddings (15%)
│  └─ text-embedding-ada-002: $1,125
├─ Vector Storage (10%)
│  └─ Pinecone: $750
└─ Infrastructure (5%)
   └─ Compute: $375

Total: $7,500/month

Cost Per Operation

// 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:

# 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:

// 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:

# 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:

// 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

┌─ AI Spending Overview ─────────────────┐
│                                         │
│  Today:        $245.50  (↑ 12%)       │
│  This Week:    $1,680   (↓ 5%)        │
│  This Month:   $6,420   (↑ 8%)        │
│  Budget:       $10,000  (64% used)     │
│                                         │
│  Top Consumers:                         │
│  1. customer-support    $2,100 (33%)   │
│  2. content-generation  $1,800 (28%)   │
│  3. code-assistant      $1,200 (19%)   │
│                                         │
└─────────────────────────────────────────┘

Trends

// 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

# 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

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

Reporting

Monthly Reports

# 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

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

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

2. Set Budgets

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

3. Review Weekly

# 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

// 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

# 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

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

Next Steps