Skip to content

requestcostmetadata: add cost-sample extractor publishing per-model t-digests#43

Open
davidbreitgand wants to merge 3 commits into
ms-llmd:mainfrom
davidbreitgand:requestcostmetadata-tdigest
Open

requestcostmetadata: add cost-sample extractor publishing per-model t-digests#43
davidbreitgand wants to merge 3 commits into
ms-llmd:mainfrom
davidbreitgand:requestcostmetadata-tdigest

Conversation

@davidbreitgand

Copy link
Copy Markdown
Contributor

kind feature

What this PR does / why we need it:

Adds the requestcostmetadata extractor plugin: on each ResponseEventType event, it reads prompt_tokens / completion_tokens from the response's usage object, looks up the model's pricing.TokenPrices, computes the per-request actual cost, and adds it into a per-model running t-digest.

At the end of each batch (i.e., the flush interval has elapsed), models that were updated during the flush interval get a digest snapshot published to their AttributeMap under pricing.CostDigestAttributeKey.

No epoch handling — the digest accumulates without bound. Epoch boundary semantics will be added in a followup PR.

No warmup counter in CostDigest or requestcostmetadata. Will be added in a followup PR.

Part of the CostGuard implementation track (proposal). Roadmap items #2 (partially).

README.md added that documents the plugin + lists known limitations.

The code also have several TODO comments that spill out of the scope of this PR. They will be captured as issues and handled in the separate PRs.

Partially fixes Issue #35

NONE

@github-actions

Copy link
Copy Markdown

⚠️ Large PR detected

Your PR is large. Please consider breaking it into multiple PRs.

The do-not-merge/hold label has been added and can be removed by the reviewers based on their judgement.

Comment thread pkg/framework/plugins/datalayer/requestcostmetadata/plugin.go Outdated
Comment thread pkg/framework/plugins/datalayer/requestcostmetadata/plugin.go Outdated
Comment thread pkg/framework/plugins/datalayer/requestcostmetadata/plugin.go
Comment thread pkg/framework/plugins/datalayer/requestcostmetadata/plugin.go Outdated

@davidbreitgand davidbreitgand left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ronenkat Please take another look at the comments, If we agree, I'll proceed with the fixes.

Comment thread pkg/framework/plugins/datalayer/requestcostmetadata/plugin.go Outdated
Comment thread pkg/framework/plugins/datalayer/requestcostmetadata/plugin.go
Comment thread pkg/framework/plugins/datalayer/requestcostmetadata/plugin.go Outdated
Signed-off-by: David Breitgand <davidbreitgand@users.noreply.github.com>
Signed-off-by: David Breitgand <davidbreitgand@users.noreply.github.com>
Signed-off-by: David Breitgand <davidbreitgand@users.noreply.github.com>
@davidbreitgand davidbreitgand force-pushed the requestcostmetadata-tdigest branch from 521861d to 36db767 Compare June 16, 2026 16:06
@github-actions

Copy link
Copy Markdown

⚠️ Large PR detected

Your PR is large. Please consider breaking it into multiple PRs.

The do-not-merge/hold label has been added and can be removed by the reviewers based on their judgement.

@davidbreitgand

Copy link
Copy Markdown
Contributor Author

@ronenkat please take another look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants