Skip to main content

Cost Tracking

Track LLM costs across providers.

Risicare automatically tracks LLM costs across 14 providers using a built-in per-model pricing table. The Cost page of the dashboard shows the cost of a project over a time range, grouped by model, provider, agent and other fields — see Dashboard Views.

Automatic Cost Calculation

The SDK captures token counts on every LLM call. The server calculates the dollar cost from those tokens and its pricing table. You don't compute cost yourself.

The server prices a span on its model id: the response model (gen_ai.response.model), or else the request model (gen_ai.request.model).

import risicare
from openai import OpenAI
 
risicare.init()
 
client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)
 
# The SDK captures token counts:
# - gen_ai.usage.prompt_tokens: 10
# - gen_ai.usage.completion_tokens: 15
#
# Risicare then computes the cost server-side and stores it as:
# - llm_cost_usd: 0.000175   (stored cost column)

How Risicare calculates cost

The server's price table wins. For a model that the table knows, the dashboard shows the server's cost when it is above zero, also when the span carries a cost of its own. The JavaScript SDK sends a cost from its own older table (llm.cost.total_usd), and a span sent over OTLP can carry gen_ai.usage.cost: the server replaces both for a known model. For a model that the table does not know, or when the server's cost is zero (for example, no token counts), a cost that the span carries is kept.

Matching. The model id of the span must equal an entry of the table or one of its aliases. The comparison ignores case, and there is no prefix match. The table has Anthropic's list prices for the current Claude models (read on 2026-10-04). A span whose model is the bare name opus, sonnet, haiku or fable is priced as the model that Claude Code uses for that name on the Anthropic API: Claude Opus 5.5, Sonnet 5.5, Haiku 4.5 and Fable 5.1. On Amazon Bedrock, Google Cloud and Microsoft Foundry, Claude Code can use an older model for sonnet or opus, and then this cost is wrong.

Words in the dashboard. The Cost page puts one of these words with a total:

  • exact: the cost does not rest on an estimate.
  • estimated: each priced span is at the fallback price ($0.15 input and $0.60 output per 1M tokens, for a model that the table does not know and a span that carries no cost).
  • mixed, N % estimated: part of the cost is at the fallback price.
  • unpriced: no span has a cost. The page never shows $0.00 for this case.

On a row of a table, an exact cost has no label. A row shows est., mixed or unpriced otherwise. On a span (the span detail), a cost at the fallback price is marked "(est.)", and a span with no cost shows no cost.

Not priced yet:

  • Some model-name forms get the fallback price: an Amazon Bedrock id of a Claude model newer than Claude 3.5 (for example anthropic.claude-sonnet-5-5 or us.anthropic.claude-…-v1:0, and ARNs), a dated Google Vertex id (claude-…@20251101), and a model name in the provider/model form (for example from LiteLLM or OpenRouter).
  • Price tiers. Batch discounts, fast or priority tiers, regional or data-residency premiums and long-context tiers are not applied. The cost is at the standard list price.
  • Some current models of other providers are not in the table yet (for example newer OpenAI and Gemini models). If the span carries no cost, they get the fallback price and the "estimated" label. If it carries a cost (for example from the JavaScript SDK), that cost is shown with no label.

Supported Providers

ProviderPricingCached Rate*
OpenAIPer-token50% cached discount
AnthropicPer-token90% to 97.5% cached discount, by model
GooglePer-token-
CoherePer-token-
MistralPer-token-
GroqPer-token-
Together AIPer-token-
Amazon BedrockPer-token-
Vertex AIPer-token-
CerebrasPer-token-
HuggingFacePer-token-
FireworksPer-token-
xAIPer-token-
OllamaFree for the local models in the pricing table (a total of only such spans shows "no cost basis recorded")-

* The cached rate is the price of cached input tokens in the price table — see Cache Token Support below.

Pricing Examples

The cost in the dashboard comes from the server's price table. It does not come from your invoice. The tables below show some of the rates in the server table (per 1M tokens).

OpenAI

ModelInputOutputCached Input
gpt-4o$2.50$10.00$1.25
gpt-4o-mini$0.15$0.60$0.075
o1$15.00$60.00$7.50
o1-mini$3.00$12.00$1.50
gpt-4-turbo$10.00$30.00-

Anthropic

ModelInputOutputCached Input
claude-fable-5-1$10.00$50.00$0.25
claude-opus-5-5$4.00$20.00$0.20
claude-sonnet-5-5$2.00$10.00$0.20
claude-opus-4-5-20251101$5.00$25.00$0.50
claude-sonnet-4-5-20250929$3.00$15.00$0.30
claude-haiku-4-5-20251001$1.00$5.00$0.10

Google

ModelInputOutput
gemini-2.0-pro$1.25$5.00
gemini-2.0-flash$0.10$0.40
gemini-1.5-pro$1.25$5.00
gemini-1.5-flash$0.075$0.30

Cache Token Support

The SDKs send cached-token and reasoning-token counts on the LLM span when the provider response gives them (Python 0.7.0 and npm 0.10.0 and later):

  • gen_ai.usage.cache_read.input_tokens: the input tokens that the provider read from its prompt cache.
  • gen_ai.usage.cache_write.input_tokens: the input tokens that the provider wrote to its prompt cache.
  • gen_ai.usage.reasoning.output_tokens: the output tokens that the model used for reasoning.
SDKProviders that send the three counts
PythonOpenAI (chat.completions.create), Anthropic (messages.create) and LiteLLM (completion, acompletion)
npmOpenAI (patchOpenAI) and Anthropic (patchAnthropic)

The other providers do not send these counts yet. A stream of OpenAI or LiteLLM gives them only in its usage chunk, so set stream_options={"include_usage": True}. The SDK sends a count only when the response gives an integer. It does not calculate or estimate a count. The OpenAI prompt count includes the cached tokens. The Anthropic input_tokens does not include the cache tokens, and the SDK sends it unchanged.

The Cost page shows these counts in its token-type card (see Dashboard Views). That card shows the share of tokens for each type and no cost for each type. Provider-side prompt caching also reduces your provider bill. The cost in the dashboard comes from the server's price table, not from your invoice.

Dashboard Views

The Cost page

The Cost item in the side navigation opens the Cost page. It has these parts:

  • Tiles: Total cost (with a word that says how exact it is), Tokens, Per trace and Unpriced.
  • A Cost by card. Buttons choose the group: Model (the default), Provider, Agent, Environment, User, Tag, Release and Failure class. Failure class stays disabled until you choose a score in the Score picker. Other controls: Hour or Day (Hour works only within 14 days), a Top select with 5, 10 (the default) or 20, and Export CSV. Each group name links to the trace list with the filter of that group and the time range.
  • A token-type card with Input (prompt), Output (completion), Cache read, Cache write and Reasoning, each with its share of tokens.
  • A price table card, Price table · as of a date. It has a box where you test a model name (and a provider, if you want), a list of the models of the time range that have no price, and a searchable table with the provider, the model, the input, output, cache read and cache write prices per 1M tokens, and the aliases. You cannot set your own prices yet: custom prices arrive in a later release.

The time range menu has the presets Last hour, Last 24 hours (the default), Last 7 days and Last 30 days. Probe traces are left out of the page, and a banner says so.

Other places

  • The trace list and the trace page: the cost of each trace.
  • The Sessions page: the cost of each session, and a Total Cost card.
  • The Agents page: a Total Cost card.
  • The agent page and the Top Performing Agents card on Home: the cost of each agent.
  • The span detail: the cost of one LLM call. An estimate from the fallback rate is marked "(est.)".

API Access

The REST API has no cost route for an API key. Use the Cost page for the cost of a project, and Export CSV to download the table of the Cost by card. The MCP server reads cost with a Secret key: cost_breakdown and top_models. Its price_table tool works with any key.

Cost Alerts

See Alerts for every field of a rule.

Alert rules are on the Alerts page, which has the tabs Alert Rules and History. A rule checks one metric of the project over a window. Each firing is recorded in History. For cost, choose the metric Cost (in USD). The metric is measured over the rule's own window, not over a calendar day.

A rule has these fields:

FieldNotes
MetricOne of 12: Error rate, Latency p50, Latency p95, Latency p99, Tool error rate, LLM error rate, Trace volume, Cost, Total tokens, Behaviour drift, Score mean and Run verdict
Operatorabove, at or above, below, at or below, equal to, not equal to. Behaviour drift and Run verdict take only above and at or above
ThresholdA number. Rate metrics are typed in percent
Window1, 5 (the default), 15, 30 or 60 minutes, or 6, 12 or 24 hours
SeverityInfo, Warning (the default), Error or Critical
Cooldown1, 5 (the default), 15 or 30 minutes, or 1, 6 or 24 hours
FilterOptional. The same filter language as the trace list, up to 2,048 characters and 32 terms
ChannelsUp to 20 channels per rule

The rule form shows a preview on the data of the last 24 hours. Members and higher roles can create, edit, test and delete rules, and switch a rule on or off. A viewer sees these controls disabled. Test sends a test firing through the channels of the rule and shows the delivery for each channel.

Channels

A channel is a Slack channel or a webhook (there is no email channel). Owners and admins add channels in Settings → Notifications: Add Slack and Add webhook. Each channel has an enable and disable switch, Test and Delete. A Slack URL starts with https://hooks.slack.com/, and a webhook URL starts with https://. A webhook channel signs each delivery with a secret that is shown once, when you add the channel. Webhooks that subscribe to alert.triggered on the Webhooks page keep working beside channels — see Webhooks.

Cost Optimization

Cost-oriented fix recommendations belong to diagnosis, which is held for the beta (see Self-Healing). Risicare does not run a separate cost-optimization analysis.

Next Steps