Repository navigation
Add usage history per API key and model - #441
Merged
Merged
Conversation
The usage endpoint returns only today's totals per key, summed across models. Add /config/quota/usage/history: daily requests and tokens per API key and model over a date range, for the caller's org, with revoked keys included. One join through api_keys replaces a query per key. Signed-off-by: Priyanshu-u07 <connect.priyanshu8271@gmail.com>
So the history can be read for an org in-process, not only through the endpoint. The endpoint keeps its checks and calls it; behaviour is unchanged. Signed-off-by: Priyanshu-u07 <connect.priyanshu8271@gmail.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.
/config/quota/usagereturns only today's totals per key, summed across models, so there's no way to see usage per model or for past days.Add
GET /management/config/quota/usage/history?start=&end=: daily requests and prompt/completion/total tokens per API key and model, for the caller's org.usage_statstoapi_keys(usage is stored asapikey:<id>), instead of a query per key.key_active: false, since their usage still counts.ORG_VIEW, like the existing endpoint. The range defaults to the last 30 days and is limited to 366.persist_usage_dbwrites them).Tests: 4 run in CI (permission, no org, invalid ranges). One checks the query against Postgres and skips without
TEST_DATABASE_URL. I ran it against a Postgres with the repo schema: it passes, and fails if the org filter is removed. Full suite with the CI ignore list: 0 failures.