Skip to Content
FeaturesCost Tracking

Cost Tracking

Track your AI costs by model, customer, feature, and more.

How Cost Tracking Works

Every API call through AiSpendTrack is tracked with:

  1. Model used - Which AI model handled the request
  2. Token counts - Prompt tokens + completion tokens
  3. Cost - Calculated from current pricing
  4. Timestamp - When the call was made
  5. Status - Success, error, rate limit, etc.

This data appears in your dashboard within 10 seconds.

Cost by Model

See which models are costing you the most.

Tracked automatically:

  • No setup required
  • Works for all OpenAI and Anthropic models
  • Updates in real-time

View in dashboard:

  • Pie chart showing model distribution
  • Table with cost per model
  • Sort by cost, calls, or name

Example insights:

  • “GPT-4 is 80% of our costs”
  • “Claude is cheaper for long documents”
  • “GPT-3.5 handles 90% of calls at 20% of cost”

Per-Customer Tracking

Track costs for each of your customers.

Setup

Add customer ID to API call headers:

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, baseURL: "https://proxy.aispendtrack.com/v1", defaultHeaders: { "x-aispendtrack-key": process.env.AISPENDTRACK_API_KEY, "x-customer-id": userId // Your customer's ID } });

The customer ID can be any string. Use your internal user ID, email, or account number.

View Per-Customer Costs

In your dashboard:

  1. Go to AnalyticsBy Customer
  2. See table of all customers
  3. Sort by cost, calls, or alphabetically
  4. Click customer to see details

Customer detail view shows:

  • Total cost for this customer
  • Number of API calls
  • Most-used models
  • Cost trend over time
  • Individual API calls

Use Cases

SaaS Pricing

  • Calculate cost per user
  • Set usage-based pricing
  • Identify high-cost users

Cost Allocation

  • Charge back costs to departments
  • Track costs per project
  • Allocate budget accurately

Profitability Analysis

  • Compare revenue vs AI costs per customer
  • Identify unprofitable accounts
  • Optimize pricing tiers

Per-Feature Tracking

Track which features are most expensive.

Setup

Add feature tag to API call headers:

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, baseURL: "https://proxy.aispendtrack.com/v1", defaultHeaders: { "x-aispendtrack-key": process.env.AISPENDTRACK_API_KEY, "x-feature": "chat-summarization" // Feature name } });

Example Feature Tags

Good feature tag examples:

  • chat-support - Customer support chatbot
  • content-generation - Blog post writer
  • code-review - Code analysis feature
  • email-summarization - Email summary feature
  • translation - Language translation

View Per-Feature Costs

Dashboard shows:

  • Total cost per feature
  • Calls per feature
  • Average cost per call
  • Trend over time

Insights:

  • “Content generation costs 10x more than chat”
  • “Email summarization is our cheapest feature”
  • “Code review needs model optimization”

Combined Tracking

Combine customer + feature tracking:

defaultHeaders: { "x-aispendtrack-key": process.env.AISPENDTRACK_API_KEY, "x-customer-id": userId, "x-feature": "chat-support" }

Now you can see:

  • Cost per customer per feature
  • Which customers use which features most
  • Feature profitability by customer segment

Cost Calculations

How We Calculate Costs

Costs are calculated using official pricing:

OpenAI Pricing (as of Feb 2024):

  • GPT-4 Turbo: $0.01/1k prompt, $0.03/1k completion
  • GPT-4: $0.03/1k prompt, $0.06/1k completion
  • GPT-3.5 Turbo: $0.0015/1k prompt, $0.002/1k completion

Anthropic Pricing:

  • Claude 3 Opus: $0.015/1k input, $0.075/1k output
  • Claude 3 Sonnet: $0.003/1k input, $0.015/1k output
  • Claude 3 Haiku: $0.00025/1k input, $0.00125/1k output

Prices are updated regularly but may lag behind provider changes. Check dashboard for current rates.

Cost Formula

cost = (prompt_tokens / 1000 × prompt_price) + (completion_tokens / 1000 × completion_price)

Example (GPT-4):

  • Prompt: 150 tokens
  • Completion: 75 tokens
  • Cost: (150/1000 × $0.03) + (75/1000 × $0.06) = $0.0045 + $0.0045 = $0.009

Cost Accuracy

Our cost calculations are:

  • ✅ Accurate to 6 decimal places
  • ✅ Based on official pricing
  • ✅ Updated when providers change pricing
  • ✅ Verified against your OpenAI/Anthropic bills

For 100% accuracy, compare our totals with your OpenAI/Anthropic invoices monthly.

Exporting Cost Data

CSV Export (Pro):

  1. Apply filters (date, model, customer)
  2. Click Export
  3. Choose format: CSV or JSON
  4. Download includes:
    • All filtered data
    • Model, customer, feature tags
    • Timestamps, costs, tokens

API Export (Pro):

Cost Budgets & Alerts

Set budgets and get alerted:

Daily Budget:

  • Set max daily spend
  • Get email/Slack alert when hit
  • Optionally pause API calls

Monthly Budget:

  • Set max monthly spend
  • Track progress (50%, 75%, 90%, 100%)
  • Email alerts at each milestone

Learn more about alerts →

Historical Data

Retention periods:

  • Free: 7 days
  • Pro: 90 days
  • Enterprise: Custom (up to 365 days)

After retention period, aggregate data remains (monthly totals, averages) but individual call records are deleted.

Next Steps

Last updated on