feat(review): expose real BYOK token/cost usage in ops stats#3992
Merged
Conversation
Closes #3925. The hosted gittensory-api Worker's ONLY possible AI activity is a maintainer's own BYOK call (the legacy Workers-AI binding path is retired; env.AI is undefined there) -- but nothing previously read back the real token/cost columns migration 0109 added to ai_usage_events for the hosted deployment. The one dashboard built for this (orb-ai-usage.json) is wired exclusively to self-host's own local reporting-export SQLite mirror, which cannot see the hosted D1. Adds sumByokAiUsageForRepoSince (real, not estimated, tokens + cost over a trailing 24h window) and wires it into the existing /v1/internal/ops/stats payload as a new byokUsage field per repo. Currently zero repos have a BYOK key configured, so this reports all zeros today -- the point is that a future burn is now observable at all, rather than requiring an ad hoc manual D1 query.
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
❌ 4 Tests Failed:
View the full list of 4 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
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
env.AIis undefined, no binding in wrangler.jsonc -- so BYOK is the ONLY AI activity a hosted deployment can ever have; currently zero repos have a BYOK key configured, so this reports all zeros today).input_tokens/output_tokens/total_tokens/cost_usdcolumns toai_usage_events, but nothing read them back for the hosted deployment -- the one dashboard built for this (orb-ai-usage.json) is wired exclusively to self-host's own local reporting-export SQLite mirror and cannot see the hosted D1's rows.sumByokAiUsageForRepoSince(real, not estimated tokens/cost, trailing 24h window) and wires it into the existing/v1/internal/ops/statspayload as a newbyokUsagefield per repo.Scope
Closes #3925above.Validation
npm run typechecknpx vitest run test/unit/ops-wire.test.ts-- 28/28 pass, including a real-usage rollup test and a zero-usage negative test.Safety