Cost Tracking
Track LLM costs across providers.
Risicare automatically tracks LLM costs across 14 providers using a built-in per-model pricing table. The LLM Cost KPI card on the main dashboard shows total spend, and the Models chart breaks down requests by model — visible in the dashboard overview.
Automatic Cost Calculation
The SDK captures token counts on every LLM call; Risicare calculates the dollar cost server-side from those tokens using current model pricing. You don't compute cost yourself.
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)Unlisted models fall back to a default price (in flight)
Server-side cost is computed from a built-in pricing table that was last refreshed February 2026, not from a live pricing feed. A model that is not in that table is currently priced with a fallback rate (pinned to gpt-4o-mini) rather than returning "unknown", and the estimate is not yet flagged as a fallback — so for a brand-new, fine-tuned (ft:…), or self-hosted model the stored cost may be approximate. (The JavaScript SDK computes cost client-side from its own table, which can carry newer models than the server table, so the same model may be priced differently depending on which SDK sent the span.) Surfacing an explicit estimated/unknown_model signal is in progress. Mainstream models present in the tables below reconcile exactly against provider invoices.
Supported Providers
| Provider | Pricing | Cached Rate* |
|---|---|---|
| OpenAI | Per-token | 50% cached discount |
| Anthropic | Per-token | 90% cached discount |
| Per-token | - | |
| Cohere | Per-token | - |
| Mistral | Per-token | - |
| Groq | Per-token | - |
| Together AI | Per-token | - |
| Amazon Bedrock | Per-token | - |
| Vertex AI | Per-token | - |
| Cerebras | Per-token | - |
| HuggingFace | Per-request | - |
| Fireworks | Per-token | - |
| xAI | Per-token | - |
| Ollama | Free (local) | - |
* The cached rate is part of the pricing model but is not yet applied end-to-end — see Cache Token Support below.
Pricing Examples
Key model pricing (per 1M tokens, as of February 2026):
OpenAI
| Model | Input | Output | Cached 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
| Model | Input | Output | Cached Input |
|---|---|---|---|
| claude-opus-4-5 | $15.00 | $75.00 | $1.50 |
| claude-sonnet-4-5 | $3.00 | $15.00 | $0.30 |
| claude-haiku-4-5 | $0.80 | $4.00 | $0.08 |
| claude-3-5-sonnet | $3.00 | $15.00 | $0.30 |
| claude-3-haiku | $0.25 | $1.25 | $0.03 |
| Model | Input | Output |
|---|---|---|
| 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
Cached-token discounting is not yet applied (in flight)
The pricing engine includes cached-input rates for OpenAI and Anthropic (the Cached Input columns above), but the SDK does not yet capture cached-token counts from provider responses, and the server-side calculator currently prices every call on its full prompt/completion tokens (cached_tokens=0). As a result, prompt-caching discounts are not reflected in llm_cost_usd today: a cache-heavy workload is over-stated for OpenAI (where cached tokens are a subset of input) and can be mis-stated for Anthropic (where cache tokens are billed separately). Treat cost for cache-heavy workloads as an upper bound until this ships.
When end-to-end cached-token support lands, the SDK will read prompt_tokens_details.cached_tokens (OpenAI) and cache_read_input_tokens (Anthropic), thread the count through the gateway and a new storage column, and the server will apply the cached rate shown in the pricing tables above. Until then, enabling provider-side prompt caching still saves you money on your provider bill — it just isn't yet reflected in the cost Risicare reports.
# Provider-side caching works as usual and reduces your real provider bill:
response = anthropic.messages.create(
model="claude-sonnet-4-5-20250929",
system=[{
"type": "text",
"text": long_prompt,
"cache_control": {"type": "ephemeral"}
}],
messages=[...]
)
# Note: the cached-token discount is not yet applied to the llm_cost_usd
# Risicare stores — that figure is computed on full input tokens for now.Dashboard Views
Cost by Provider
View total cost breakdown by provider:
OpenAI: $142.50 (45%)
Anthropic: $98.20 (31%)
Google: $45.30 (14%)
Others: $31.00 (10%)
Cost by Model
See which models cost the most:
gpt-4o: $98.50
claude-sonnet-4-5: $67.20
gpt-4o-mini: $22.00
gemini-2.0-pro: $18.30
Cost by Feature
Track costs per feature or endpoint:
/api/chat: $145.00
/api/summarize: $67.00
/api/search: $32.00
API Access
Cost data is available per-trace and per-span via the standard management API:
# Get traces with cost data
curl "https://app.risicare.ai/api/v1/traces?limit=50" \
-H "Authorization: Bearer rsk-..."Each trace includes total_cost_usd and each span includes llm_cost_usd in the response. Use the dashboard for aggregated cost breakdowns by provider, model, or time period.
Programmatic cost aggregation
A dedicated cost analytics API endpoint is on the roadmap. For now, aggregate cost data by querying traces and summing total_cost_usd, or use the dashboard's built-in cost views.
Cost Alerts
Create an alert rule that fires when daily spend crosses a threshold:
curl -X POST "https://app.risicare.ai/api/v1/alerts" \
-H "Authorization: Bearer rsk-..." \
-H "Content-Type: application/json" \
-d '{
"name": "Daily LLM spend over $100",
"metric": "daily_cost_usd",
"operator": "gt",
"threshold": 100.0,
"window_minutes": 1440,
"severity": "warning"
}'name, metric, operator, and threshold are required. Unknown fields are
rejected with 422 — the request body is strictly validated.
| Field | Required | Notes |
|---|---|---|
name | yes | Human-readable rule name |
metric | yes | Must be one of the supported metrics below |
operator | yes | gt, lt, eq, gte, lte, ne |
threshold | yes | Numeric threshold |
window_minutes | no | Evaluation window, default 5 |
severity | no | info, warning, error, critical — default warning |
channels | no | Informational label only — see delivery note below |
Supported metrics. A rule naming any other metric is skipped by the evaluator (logged as a warning) and will never fire:
error_rate · agent_failure_rate · latency_p50 · latency_p95 ·
latency_p99 · trace_volume · daily_cost_usd · total_tokens
Webhook is the only alert channel, and it is unverified
channels does not route anything today. When a rule fires, the alert worker
emits an alert.triggered webhook event to every webhook in the project
subscribed to it — that is the only delivery path there is.
Webhook delivery has never been observed reaching an endpoint (see Webhooks). Treat cost alerting as unverified end to end: the rule will evaluate and fire, but whether you receive anything is untested.
Cost Optimization
When the diagnosis pipeline analyzes a budget- or resource-related error, it can surface cost-oriented fix recommendations, such as a "use a cheaper model when approaching budget" suggestion. These appear as recommendations in the diagnosis output — they are not auto-applied (fix deployment is on the roadmap; see Self-Healing).
- Model downgrade suggestions: e.g. "Switch to a cheaper model when approaching the budget limit"
- Caching / token-reduction hints surfaced alongside a diagnosis, where applicable
Risicare does not currently run a standalone, always-on cost-optimization analysis independent of the diagnosis pipeline.