dexcost
Rust

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 captureTrackedOpenAI, TrackedAnthropic, and TrackedGemini wrapper clients record provider, model, input/output tokens, latency, and computed cost for every call inside a tracked task. Use task.record_llm_call to record calls from any provider explicitly.
  • HTTP / non-LLM cost capturetask.record_cost records an explicit non-LLM service fee in exact-precision Decimal; task.record_usage auto-computes cost from a registered rate; the bundled service catalog covers non-LLM HTTP costs when HTTP tracking is enabled.
  • Retry trackingtask.mark_retry tags a retry event with a reason string; the optional retry heuristic engine, enabled via TaskOptions::heuristics, can detect retries automatically by inspecting recent LLM call patterns.
  • Customer / project / task attributionTaskOptions fields customer_id, project_id, experiment_id, and variant propagate attribution through the returned TrackedTask; nested tasks created inside task.scope(...) pick up parent_task_id automatically.
  • Local SQLite buffer + background sync — events are written to a local SQLite file (~/.dexcost/buffer.db by 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 the RateRegistry.

Requirements

Async Rust with the Tokio runtime. Rust edition 2021 (Rust 1.75+ for stable async trait support).

Next steps

  • Installationcargo add dexcost and optional Cargo features.
  • Quickstart — initialize the SDK and capture your first attributed cost.
  • Instrumentation — wrapper client usage, explicit recording, and HTTP tracking.
  • Configuration — all Config fields, environment variables, and privacy options.
  • API Reference — full public API: init, start_task, TrackedOpenAI, record_llm_call, record_cost, flush, close, and more.

On this page