token-budget-pool 0.1.0

Shared token + dollar budget across concurrent LLM tasks. Thread-safe, returns BudgetExceeded when a record would push past a cap. Zero deps.
Documentation
  • Coverage
  • 100%
    23 out of 23 items documented1 out of 12 items with examples
  • Size
  • Source code size: 23.61 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 496.94 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 16s Average build duration of successful builds.
  • all releases: 16s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • MukundaKatta/token-budget-pool
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • MukundaKatta

token-budget-pool

crates.io docs.rs

Shared token + dollar budget across N concurrent LLM tasks. Thread-safe, rejects records that would push past a cap (totals unchanged on rejection), zero deps.

Usage

use token_budget_pool::{BudgetPool, Caps};
use std::sync::Arc;

let pool = Arc::new(BudgetPool::with_caps(Caps {
    max_input_tokens: Some(10_000),
    max_output_tokens: Some(5_000),
    max_total_tokens: None,
    max_cost_usd: Some(1.0),
}));

// Hand a clone to every task that spends from the budget.
let p = pool.clone();
std::thread::spawn(move || {
    if let Err(e) = p.record(1_000, 500, 0.05) {
        eprintln!("budget exceeded: {e}");
    }
});

License

MIT or Apache-2.0.