LLM Usage & Costs

Track your AI usage and estimated costs

<%= form_with url: settings_llm_usage_path, method: :get, class: "flex gap-4 items-end flex-wrap" do |f| %>
<%= f.label :start_date, "Start Date", class: "block text-sm font-medium text-primary mb-1" %> <%= f.date_field :start_date, value: @start_date, class: "rounded-lg border border-primary px-3 py-2 text-sm bg-container-inset text-primary w-full" %>
<%= f.label :end_date, "End Date", class: "block text-sm font-medium text-primary mb-1" %> <%= f.date_field :end_date, value: @end_date, class: "rounded-lg border border-primary px-3 py-2 text-sm bg-container-inset text-primary w-full" %>
<%= render DS::Button.new(variant: :primary, size: :md, type: "submit", text: "Filter", class: "md:w-auto w-full justify-center") %> <% end %>
<%= icon "activity", class: "w-5 h-5 text-secondary" %>

Total Requests

<%= number_with_delimiter(@statistics[:total_requests]) %>

<%= icon "hash", class: "w-5 h-5 text-secondary" %>

Total Tokens

<%= number_with_delimiter(@statistics[:total_tokens]) %>

<%= number_with_delimiter(@statistics[:total_prompt_tokens]) %> prompt / <%= number_with_delimiter(@statistics[:total_completion_tokens]) %> completion

<%= icon "dollar-sign", class: "w-5 h-5 text-secondary" %>

Total Cost

$<%= sprintf("%.2f", @statistics[:total_cost]) %>

<%= icon "trending-up", class: "w-5 h-5 text-secondary" %>

Avg Cost/Request

$<%= sprintf("%.4f", @statistics[:avg_cost]) %>

<% if @statistics[:requests_with_cost] < @statistics[:total_requests] %>

Based on <%= number_with_delimiter(@statistics[:requests_with_cost]) %> of <%= number_with_delimiter(@statistics[:total_requests]) %> requests with cost data

<% end %>
<% if @statistics[:by_operation].any? %>

Cost by Operation

<% @statistics[:by_operation].each do |operation, cost| %>
<%= operation.humanize %> $<%= sprintf("%.4f", cost) %>
<% end %>
<% end %> <% if @statistics[:by_model].any? %>

Cost by Model

<% @statistics[:by_model].each do |model, cost| %>
<%= model %> $<%= sprintf("%.4f", cost) %>
<% end %>
<% end %>

Recent Usage

<% if @llm_usages.any? %> <% @llm_usages.each do |usage| %> "> <% end %>
Date Operation Model Tokens Cost
<%= usage.created_at.strftime("%b %d, %Y %I:%M %p") %> <%= usage.operation.humanize %> <%= usage.model %> <% if usage.failed? %>
<%= icon "alert-circle", class: "w-4 h-4 text-red-600 theme-dark:text-red-400" %> Failed
<% else %> <%= number_with_delimiter(usage.total_tokens) %> (<%= number_with_delimiter(usage.prompt_tokens) %>/<%= number_with_delimiter(usage.completion_tokens) %>) <% end %>
<%= usage.formatted_cost %>
<% else %>

No usage data found for the selected period

<% end %>
<%= icon "info", class: "w-5 h-5 text-blue-600 mt-0.5" %>

About Cost Estimates

Costs are estimated based on OpenAI's pricing as of 2025. Actual costs may vary. Pricing is per 1 million tokens and varies by model. Custom or self-hosted models will show "N/A" and are not included in cost totals.