feat: per-key usage history and token count tracking (Stories 3.1 + 3.2)#132
Merged
farovictor merged 1 commit intomainfrom Apr 5, 2026
Merged
feat: per-key usage history and token count tracking (Stories 3.1 + 3.2)#132farovictor merged 1 commit intomainfrom
farovictor merged 1 commit intomainfrom
Conversation
- pkg/usage: Event model, MemoryStore, SQLStore with pagination
- routes: GET /v1/keys/{id}/usage endpoint (filterable by from/to, paginated)
- proxy: records a usage event after every proxied request (latency, status code, service)
- proxy: parses prompt/completion/total tokens from OpenAI-compatible responses when BIFROST_TRACK_TOKENS=true
- config: TrackTokens() and UsageRetentionDays() env vars
- migrations: 009_create_usage_events.sql
- tests: usage endpoint and proxy-records-event coverage
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
GET /v1/keys/{id}/usage— paginated usage event history per virtual key, filterable by?from=and?to=(RFC3339)usage.Eventafter every request (latency, status code, target service)BIFROST_TRACK_TOKENS=truepkg/usagepackage:Eventmodel,MemoryStore,SQLStore,Storeinterface009_create_usage_events.sql+--migrate-onlyincludesusage_eventstableTest plan
TestListKeyUsage_Empty— 200 with empty events arrayTestListKeyUsage_NotFound— 404 for unknown keyTestListKeyUsage_WithEvents— returns pre-seeded events with correct totalTestListKeyUsage_InvalidFrom— 400 on bad RFC3339 dateTestProxyRecordsUsageEvent— proxy call records one event in the usage store🤖 Generated with Claude Code