LLM spend tracking and budgets for Rails — by user, feature, or any tag, in your own database, no proxy.
README
LLM spend tracking and budgets for Rails — by user, feature, or any tag, in your own database, no proxy.
Not Langfuse, Helicone, or LiteLLM. No prompts, no traces, no replay. Spend attribution only.
Requires Ruby 3.3+, Rails 8.0+, PostgreSQL or MySQL. Built for a Rails monolith, not multiple services.
<picture> <source media="(prefers-color-scheme: dark)" srcset="docs/dashboard-overview-dark.png"> <img alt="LLM Cost Tracker dashboard" src="docs/dashboard-overview-light.png"> </picture>
Shown with RubyLLM; the flow is identical for the official OpenAI and Anthropic SDKs — swap the gem and the instrument name (see the cookbook).
# Gemfile
gem "llm_cost_tracker"
gem "ruby_llm"
bin/rails llm_cost_tracker:setup
Runs the install generator, drops a price snapshot, migrates the database, and verifies via llm_cost_tracker:doctor. Then enable the integration in the generated config/initializers/llm_cost_tracker.rb:
LlmCostTracker.configure do |config|
config.tags.default = -> { { environment: Rails.env } }
config.instrument :ruby_llm
end
Your RubyLLM calls stay unchanged — every chat, embedding, transcription, image, and moderation call now lands in the ledger. Tag them to attribute spend:
LlmCostTracker.with_tags(user_id: Current.user&.id, feature: "chat") do
RubyLLM.chat.ask("Hello")
end
Mount the dashboard in config/routes.rb. The engine ships without authentication, so put it behind yours:
authenticate :admin do
mount LlmC