feat(backend): per-app token usage & cost attribution#13
Open
varunmaggo wants to merge 1 commit into
Open
Conversation
Extends the existing per-app metrics pipeline (which already tracks request counts, latency percentiles, and error rates) to also attribute LLM token usage and computed cost to each published agent app. - New cost-model module: pure pricing table (USD/1M tokens per model) with a flagged fallback for unknown models. Cost is computed in integer micro-USD so it accumulates safely with DynamoDB atomic ADD counters (no float drift). Negative / non-finite token counts clamp to zero. - AccessLogEntry gains optional model / inputTokens / outputTokens; older log lines without them are treated as zero (backwards compatible). - computeMetrics sums totalInputTokens / totalOutputTokens / totalCostMicroUsd; upsert ADDs them to the hourly METRICS# item. - getAppMetrics surfaces token totals and cost (USD) plus per-bucket token/cost in the time series. - GraphQL AppMetrics / AppMetricsBucket extended with the new fields (all default to 0, so existing buckets and the dashboard keep working). - Unit tests for the cost model and token/cost aggregation; existing metrics property tests remain green. Frontend dashboard surfacing and per-app budget alerting are follow-ups. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jo23wVkjxvhMhEbyWxngEv
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.
Extends the existing per-app metrics pipeline (which already tracks request counts, latency percentiles, and error rates) to also attribute LLM token usage and computed cost to each published agent app.
Frontend dashboard surfacing and per-app budget alerting are follow-ups.
Claude-Session: https://claude.ai/code/session_01Jo23wVkjxvhMhEbyWxngEv
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.