Skip to main content

Overview

Anyway automatically tracks the cost of every LLM API call, helping you:
  • Monitor spending in real-time
  • Attribute costs to users, features, or teams
  • Identify expensive operations
  • Optimize token usage

Automatic Cost Calculation

Both the Python and JavaScript SDKs automatically calculate costs based on bundled pricing data. Costs are added as span attributes:
  • gen_ai.usage.input_cost — Input token cost (USD)
  • gen_ai.usage.output_cost — Output token cost (USD)
  • gen_ai.usage.cost — Total cost (USD)

Supported Models

Pricing is included for 150+ models from these providers:
The SDK ships with a default pricing file that is updated with each release. You can also provide custom pricing — see below.

Custom Pricing

Provide your own pricing data to add models or override prices:
To disable cost calculation entirely:

Pricing JSON Format

  • promptPrice: Cost per 1K input tokens (USD)
  • completionPrice: Cost per 1K output tokens (USD)

Model Matching

The SDK matches model names using a three-tier strategy:
  1. Exact matchgpt-4o-mini matches gpt-4o-mini
  2. Date suffix strippedgpt-4o-2024-08-06 matches gpt-4o
  3. Longest prefixgpt-4o-mini-custom matches gpt-4o-mini
Unknown models are silently skipped — no error, just no cost attributes on that span.

Cost Attribution

Use association properties to track costs by user, feature, or team:
Then filter costs in the dashboard by these attributes.

Cost Dashboard

The Cost Dashboard shows:
  • Total spend — Current period and trend
  • Cost by model — Which models cost the most
  • Cost by association — Filter by user, team, or feature
  • Daily trends — Spending over time

Cost Optimization Tips

Not every task needs a large model. Use gpt-4o-mini or claude-3-haiku for:
  • Classification tasks
  • Simple extractions
  • Formatting/transformation
Shorter prompts = lower costs:
  • Remove redundant instructions
  • Use examples efficiently
  • Consider prompt caching
Prevent runaway costs with max_tokens:

Next Steps

Usage Limits

Set usage quotas

Payments

Create payment links and accept payments