llm_cost_tracker is a self-hosted Ruby gem for tracking LLM API spending in Rails applications. It intercepts Faraday HTTP responses, parses token usage from providers like OpenAI, Anthropic, and Google Gemini, prices them locally using a bundled prices file, and stores events in your own database via ActiveRecord. Key features include flexible tagging (by user, feature, environment, etc.), budget guardrails with configurable behaviors (notify, raise, or block requests), a built-in Rails Engine dashboard with CSV export, ActiveSupport::Notifications integration, custom storage backends, and support for OpenAI-compatible providers. No external proxy or SaaS service is required — all data stays in your own database.

8m read timeFrom github.com
Post cover image
Table of contents
WhyInstallationQuick try (no database)UsageConfigurationBudget enforcementQuerying costsDashboard (optional)ActiveSupport::NotificationsCustom storage backendOpenAI-compatible providersCustom parserSupported providersSafetyKnown limitationsDevelopmentLicense

Sort: