Skip to content

Separate estimated savings from billed usage and exclude count_tokens from savings totals #18

Open

Description

@timfewi

The status line presents an accumulated “saved” token count, but the value combines different quantities and can increase without a successful generation request. It should be clearly identified as an estimate and should not accumulate non-billable/preflight transformations as realized savings.

Reviewed main at e86ba25330d7038950e37de34d796cd34519e7eb (package version 0.5.0). This report is based on source inspection; no live provider benchmark was run.

Concrete accounting problems:

  • transformRequest uses fixed price constants and character-based token estimates, regardless of the requested model. It converts estimated net dollars back into a token-equivalent value and clamps negative results to zero.
  • server.ts sends both /v1/messages and /v1/messages/count_tokens through the same transformation/accounting path. addSaving runs before the upstream response, so count-only calls and failed upstream requests can increase the total.
  • Hooks add their own content-length/token deltas to the same counter before confirming that the harness applied a replacement.
  • stats.ts ignores non-positive values, so negative estimated net savings cannot offset positive ones. The status line displays the aggregate simply as “saved”.

Please:

  • Keep estimated input-token reduction, estimated net cost, and observed provider usage as separate fields with explicit units.
  • Label estimates as estimates and expose their pricing/tokenization assumptions; use the selected model's rates where relevant.
  • Exclude count-only requests from realized generation savings and avoid booking savings for rejected/failed upstream requests.
  • Preserve negative net-cost estimates rather than only accumulating favorable results.
  • Add tests for repeated count_tokens calls, upstream failure, a compaction whose estimated cost exceeds its benefit, and different model pricing.

The key acceptance criterion is that the displayed figure cannot be mistaken for measured billing savings.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions