Overview
The Rust SDK brings Agent Unit Economics to async (Tokio) Rust applications by wrapping LLM clients or recording calls explicitly with full customer, project, and task attribution.
The dexcost Rust SDK brings Agent Unit Economics to async (Tokio) Rust applications. Because Rust cannot monkey-patch at runtime, the integration model is wrapper clients: you pass token counts from your LLM responses to TrackedOpenAI, TrackedAnthropic, or TrackedGemini, or record calls explicitly on a TrackedTask with task.record_llm_call. Either way, every LLM cost, non-LLM service fee, and retry is attributed to a customer, project, and task, with costs auto-priced from bundled model data.
Key capabilities
- LLM cost capture —
TrackedOpenAI,TrackedAnthropic, andTrackedGeminiwrapper clients record provider, model, input/output tokens, latency, and computed cost for every call inside a tracked task. Usetask.record_llm_callto record calls from any provider explicitly. - HTTP / non-LLM cost capture —
task.record_costrecords an explicit non-LLM service fee in exact-precisionDecimal;task.record_usageauto-computes cost from a registered rate; the bundled service catalog covers non-LLM HTTP costs when HTTP tracking is enabled. - Retry tracking —
task.mark_retrytags a retry event with a reason string; the optional retry heuristic engine, enabled viaTaskOptions::heuristics, can detect retries automatically by inspecting recent LLM call patterns. - Customer / project / task attribution —
TaskOptionsfieldscustomer_id,project_id,experiment_id, andvariantpropagate attribution through the returnedTrackedTask; nested tasks created insidetask.scope(...)pick upparent_task_idautomatically. - Local SQLite buffer + background sync — events are written to a local SQLite file (
~/.dexcost/buffer.dbby default) first; a background pusher flushes them to the Control Layer in configurable batches every 5 seconds, so data is never lost on a crash. - Pricing engine — bundled model pricing is available fully offline; custom per-model rates can be registered via
pricing_engine().set_custom_pricing; non-LLM service rates are registered via theRateRegistry.
Requirements
Async Rust with the Tokio runtime. Rust edition 2021 (Rust 1.75+ for stable async trait support).
Next steps
- Installation —
cargo add dexcostand optional Cargo features. - Quickstart — initialize the SDK and capture your first attributed cost.
- Instrumentation — wrapper client usage, explicit recording, and HTTP tracking.
- Configuration — all
Configfields, environment variables, and privacy options. - API Reference — full public API:
init,start_task,TrackedOpenAI,record_llm_call,record_cost,flush,close, and more.