relay-stats
Usage and cost dashboard from Anthropic/OpenAI org API or local log scraper.
Overview
relay-stats fetches rolling cost and token usage data from provider APIs (Anthropic, OpenAI) if admin keys are configured, with fallback to scraping local ~/.claude/ session files. It computes per-model costs using cortex.yaml pricing and calculates routing savings by comparing chosen model cost against baseline model cost.
Usage
Add as a dependency:
[]
= { = "../relay-stats" }
= { = "../relay-core" }
= { = "1" }
Example:
use StatsEngine;
use CortexConfig;
use Path;
async
Public API
StatsEngine::new(config)- initialize from CortexConfigStatsEngine::fetch_summary(days)- fetch rolling usage (async)UsageSummary- contains by_model vec, total_cost_usd, routing_savings_usd, sourceModelUsage- per-model breakdown with token counts and costStatsSource- enum: ProviderApi, LocalLogScraper, or Unavailable
Dependencies
relay-core- config, database, typesrusqlite- query routing decisions for savingstokio/reqwest- async HTTP for provider APIschrono- date range calculationskeyring- OS keychain access for provider admin keys
Part of Relay
relay-stats is one of six MIT-licensed pillar crates. It tracks usage alongside relay-memory (tiered storage), relay-notes (wikilinks), relay-router (task classification), and relay-miner (pattern mining). Three architecture crates (relay-mcp, relay-daemon, relay-cli) assemble all pillars into the MCP server.
See the workspace README and LICENSING.md for details.
License
MIT. See LICENSE.