# token-budget-pool
[](https://crates.io/crates/token-budget-pool)
[](https://docs.rs/token-budget-pool)
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
```rust
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();
eprintln!("budget exceeded: {e}");
}
});
```
## License
MIT or Apache-2.0.