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:
ProviderExample Models
OpenAIgpt-4o, gpt-4o-mini, gpt-4-turbo, o1, o1-mini
Anthropicclaude-sonnet-4-20250514, claude-3.5-sonnet, claude-3-haiku
Googlegemini-1.5-pro, gemini-1.5-flash, gemini-2.0-flash
Metallama-3.1-405b, llama-3.1-70b, llama-3.1-8b
Mistralmistral-large, mistral-medium, mistral-small
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:
from anyway.sdk import Traceloop

Traceloop.init(
    app_name="my-app",
    pricing_json_path="./pricing.json",
)
To disable cost calculation entirely:
Traceloop.init(
    app_name="my-app",
    pricing_enabled=False,
)

Pricing JSON Format

{
  "chat": {
    "gpt-4o-mini": {
      "promptPrice": 0.00015,
      "completionPrice": 0.0006
    },
    "custom-model": {
      "promptPrice": 0.001,
      "completionPrice": 0.002
    }
  }
}
  • 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:
from anyway.sdk.decorators import workflow, task

@workflow(name="user-query", association_properties={
    "user_id": "user-123",
    "team": "growth",
    "feature": "chatbot",
})
def handle_query(query: str):
    return call_llm(query)
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:
response = client.chat.completions.create(
    model="gpt-4o",
    max_tokens=500,
    messages=[...]
)

Next Steps

Usage Limits

Set usage quotas

Payments

Create payment links and accept payments