LEVEL 1 · STARTER

Token Counter and Cost Meter

Build an explicit approximate tokenizer, exact recorded-usage accounting, rate-card cost calculation and budget admission. Estimates are labeled and never presented as provider tokenizer counts. Prices are fixture inputs rather than claims about current provider pricing.

4 stages~8 hoursRustcore
Estimate text with a documented boundValidate recorded usagePrice with checked integersAdmit work against a ledger
YOU END UP WITH

Usage reconciliation explaining why real billing differs from preflight estimates.

USEFUL FOR
  • Usage reconciliation explaining why real billing differs from preflight estimates.
  • Rates are explicit fixture inputs in integer nano-dollars per token, not current provider prices.
PROJECT OUTLINE

Token Counter and Cost Meter in 4 stages

Account for usage and budgets with integer arithmetic.

  1. Estimate text with a documented bound

    Count Unicode scalar values and use a configurable characters-per-token ratio with ceiling division.

    starter · ~2 hours · Rust

    Count scalarsRead ratioCeiling divisionLabel estimate
  2. Validate recorded usage

    Cached input is a subset of input, never an extra token category to add twice.

    core · ~2 hours · Rust

    Parse countersCheck unsignedCached subsetUsage record
  3. Price with checked integers

    The fixture rate card uses nano-dollars per token.

    core · ~2 hours · Rust

    Uncached chargeCache chargeOutput chargeChecked sum
  4. Admit work against a ledger

    Reserve a quoted amount only if spent plus quote is within the configured limit.

    core · ~2 hours · Rust

    Read ledgerChecked additionCompare limitCommit reservation

Lessons this project uses

All projects · Course catalog · Source on GitHub