Skip to content

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

Closed
davidbreitgand wants to merge 3 commits into
tdigestfrom
requestcostmetadata-tdigest
Closed

requestcostmetadata: add cost-sample extractor publishing per-model t-digests#1
davidbreitgand wants to merge 3 commits into
tdigestfrom
requestcostmetadata-tdigest

Conversation

@davidbreitgand

Copy link
Copy Markdown
Owner

/kind feature

What this PR does / why we need it:

Depends on PR ms-llmd#42 (the tdigest branch, which adds pricing.CostDigest and the caio/go-tdigest/v5 dependency). This branch is opened against tdigest, not main (I will rebase onto main after PR#42 lands).

Adds the requestcostmetadata extractor: on each ResponseEventType event, it reads prompt_tokens / completion_tokens from the response's usage block, looks up the model's pricing.TokenPrices, computes the per-request 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 ms-llmd#2/ms-llmd#3 (partially).

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

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

Partially fixes ms-llmd#35

Release note (write NONE if no user-facing change):

NONE

…md#42)

* Adds CostDigest t-digest data structure to the pricing package

Signed-off-by: David Breitgand <davidbreitgand@users.noreply.github.com>

* Removes Cloneable contract tests to address reviewer's feedback

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>
Signed-off-by: David Breitgand <davidbreitgand@users.noreply.github.com>
@davidbreitgand davidbreitgand force-pushed the requestcostmetadata-tdigest branch from 545eb2f to 521861d Compare June 13, 2026 15:16
@davidbreitgand

Copy link
Copy Markdown
Owner Author

Superseded by PR#43 in ms-llmd

The prerequisite (CostDigest + caio/go-tdigest dependency) landed on
upstream main as ms-llmd#42, so this PR has been rebased onto upstream main
and reopened directly against ms-llmd. Closing here to consolidate
review on the upstream PR.

Thank you!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant