aicost
A Rust library to compute LLM usage costs based on the genai crate types.
Features
- Supports multiple providers (OpenAI, Anthropic, Gemini, DeepSeek, Groq, xAI, Fireworks, Together, Zai).
- Handles normal tokens, cached tokens (read/write), and reasoning tokens.
- Provides granular cost breakdown via the
AiCoststruct. - Integrates with genai via
ModelIdenandUsage.
Usage
use compute;
use Usage;
// From a genai::chat::Usage object
let usage = Usage ;
let cost = compute?;
println!;
println!;
println!;
Using ModelIden
If you are using the genai crate, you can compute costs directly using ModelIden.
let cost = compute_iden?;
Structure
The AiCost struct provides a detailed breakdown: