feat(dashboard): track real API call count per session (salvages #10140)#14004
Merged
Conversation
Adds schema v7 'api_call_count' column. run_agent.py increments it by 1 per LLM API call, web_server analytics SQL aggregates it, frontend uses the real counter instead of summing sessions. The 'API Calls' card on the analytics dashboard previously displayed COUNT(*) from the sessions table — the number of conversations, not LLM requests. Each session makes 10-90 API calls through the tool loop, so the reported number was ~30x lower than real. Salvaged from PR #10140 (@kshitijk4poor). The cache-token accuracy portions of the original PR were deferred — per-provider analytics is the better path there, since cache_write_tokens and actual_cost_usd are only reliably available from a subset of providers (Anthropic native, Codex Responses, OpenRouter with usage.include). Tests: - schema_version v7 assertion - migration v2 -> v7 adds api_call_count column with default 0 - update_token_counts increments api_call_count by provided delta - absolute=True sets api_call_count directly - /api/analytics/usage exposes total_api_calls in totals
5b932d4 to
f1b6a90
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a real
api_call_countcounter per session so the analytics dashboard's "API Calls" card shows actual LLM requests, not session count (which was ~30x too low).Salvages the
api_call_countpiece of #10140 by @kshitijk4poor. Cache-token / cost-total changes from the original PR were deferred — per-provider analytics is the right path sincecache_write_tokensandactual_cost_usdare only reliable on a subset of providers (Anthropic native, Codex Responses, OpenRouter withusage.include, Nous).Changes
hermes_state.py: schema v7 migration +api_call_countcolumn +api_call_countparam onupdate_token_counts(increment mode + absolute mode)run_agent.py: passapi_call_count=1per LLM callhermes_cli/web_server.py: all 3 analytics queries aggregateapi_call_count→api_calls/total_api_callsweb/src/lib/api.ts: TS interfaces for new fieldsweb/src/pages/AnalyticsPage.tsx: API Calls card usestotal_api_callsValidation
COUNT(*) FROM sessions(conversations)tests/test_hermes_state.py+tests/hermes_cli/test_web_server.py)api_call_count=0)