Guide

Cost & Token Tracking

2Signal automatically tracks token usage and calculates cost for every LLM call when you use a wrapped client. Here's how it works.

How Cost is Calculated

When you wrap an LLM client with wrap_openai, wrap_anthropic, or any other wrapper, 2Signal captures:

  1. Model name from the API response
  2. Token counts (prompt tokens + completion tokens) from the usage field
  3. Cost calculated as: (prompt_tokens × input_price) + (completion_tokens × output_price)

Costs are stored per-span and aggregated up to the trace level as total_cost.

Supported Models & Pricing

The SDK includes a built-in pricing table for 50+ models. Prices reflect the latest public pricing from each provider.

OpenAI

ModelInput ($/1M tokens)Output ($/1M tokens)
gpt-4o$2.50$10.00
gpt-4o-mini$0.15$0.60
gpt-4-turbo$10.00$30.00
gpt-4$30.00$60.00
gpt-3.5-turbo$0.50$1.50
o3-mini$1.10$4.40

Anthropic

ModelInput ($/1M tokens)Output ($/1M tokens)
claude-opus-4$15.00$75.00
claude-sonnet-4$3.00$15.00
claude-haiku-4$0.80$4.00
claude-3-5-sonnet$3.00$15.00
claude-3-opus$15.00$75.00

Google

ModelInput ($/1M tokens)Output ($/1M tokens)
gemini-2.5-pro$1.25$10.00
gemini-2.5-flash$0.15$0.60
gemini-2.0-flash$0.10$0.40
gemini-1.5-pro$1.25$5.00
gemini-1.5-flash$0.075$0.30

Other Providers

ProviderModels
Mistralmistral-large, mistral-medium, mistral-small, codestral, ministral-8b
Coherecommand-r-plus, command-r
Groqllama-3.3-70b, llama-3.1-8b, mixtral-8x7b, gemma2-9b

Unsupported Models

If a model isn't in the pricing table, 2Signal still captures the token counts but reports cost as $0.00. You can still use the Cost evaluator with custom thresholds, or submit costs manually via the API:

# Manual cost submission in a span
with ts.span(name="llm-call", span_type="llm") as ctx:
    result = my_custom_llm(prompt)
    ctx["output"] = result
    ctx["usage"] = {"prompt_tokens": 500, "completion_tokens": 200}
    ctx["cost"] = 0.015  # USD

Usage Tracking

Beyond per-request costs, 2Signal tracks monthly usage at the organization level:

MetricDescription
Trace countTotal traces ingested this month
Span countTotal spans across all traces
Eval run countTotal evaluator executions

Plan Limits

PlanTraces/monthEvals/monthRetention
Free1,0005007 days
Pro10,0005,00030 days
Team50,00025,00090 days
EnterpriseUnlimitedUnlimitedUnlimited

Usage Alerts

2Signal sends email notifications to organization owners and admins at:

  • 80% of your monthly trace limit — warning to review usage
  • 100% of your monthly trace limit — hard limit reached, new traces rejected

Alerts are sent once per threshold per month and include a link to the billing page for plan upgrades.

Have questions? Join our community!

Connect with other developers and the 2Signal team.

Join Discord