Skip to content

feat(dashboard): track real API call count per session (salvages #10140)#14004

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-3482e10c
Apr 22, 2026
Merged

feat(dashboard): track real API call count per session (salvages #10140)#14004
teknium1 merged 1 commit into
mainfrom
hermes/hermes-3482e10c

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Adds a real api_call_count counter 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_count piece of #10140 by @kshitijk4poor. Cache-token / cost-total changes from the original PR were deferred — per-provider analytics is the right path since cache_write_tokens and actual_cost_usd are only reliable on a subset of providers (Anthropic native, Codex Responses, OpenRouter with usage.include, Nous).

Changes

  • hermes_state.py: schema v7 migration + api_call_count column + api_call_count param on update_token_counts (increment mode + absolute mode)
  • run_agent.py: pass api_call_count=1 per LLM call
  • hermes_cli/web_server.py: all 3 analytics queries aggregate api_call_countapi_calls / total_api_calls
  • web/src/lib/api.ts: TS interfaces for new fields
  • web/src/pages/AnalyticsPage.tsx: API Calls card uses total_api_calls

Validation

Before After
"API Calls" card COUNT(*) FROM sessions (conversations) real LLM-request counter
targeted tests 238/238 pass (tests/test_hermes_state.py + tests/hermes_cli/test_web_server.py)
v2 → v7 migration n/a verified (legacy rows get api_call_count=0)

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
@teknium1 teknium1 force-pushed the hermes/hermes-3482e10c branch from 5b932d4 to f1b6a90 Compare April 22, 2026 12:51
@teknium1 teknium1 merged commit 5fb1431 into main Apr 22, 2026
10 of 11 checks passed
@teknium1 teknium1 deleted the hermes/hermes-3482e10c branch April 22, 2026 12:52
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard labels Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants