Expand description
§dexcost
Rust SDK for dexcost – an Agent Unit Economics platform. Track LLM costs, non-LLM service fees, and retry waste attributed to customers, projects, and workflows.
§Quickstart
use dexcost::{Config, TaskOptions, TaskStatus, init, start_task, flush, close};
#[tokio::main]
async fn main() {
init(Config::default()).unwrap();
let mut task = start_task("resolve_ticket", TaskOptions {
customer_id: Some("acme-corp".into()),
project_id: Some("support".into()),
..Default::default()
}).await.unwrap();
task.record_llm_call("openai", "gpt-4o", 1000, 500, None, None, None)
.await
.unwrap();
task.end(TaskStatus::Success).await.unwrap();
flush().await.unwrap();
close();
}See PARITY.md
for the Python ↔ Rust parity matrix and a list of idiomatic differences.
Re-exports§
pub use config::Config;pub use core::context::clear_dexcost_context;pub use core::context::create_auto_task;pub use core::context::get_current_task;pub use core::context::get_dexcost_context;pub use core::context::set_context;pub use core::context::with_task;pub use core::context::DexcostContext;pub use core::heuristics::RetryHeuristicEngine;pub use core::models::CostConfidence;pub use core::models::CostEvent;pub use core::models::EventType;pub use core::models::PricingSource;pub use core::models::Task;pub use core::models::TaskStatus;pub use core::session::get_session_manager;pub use core::session::SessionManager;pub use core::tracker::HeuristicConfig;pub use core::tracker::RecordCostOptions;pub use core::tracker::RecordLlmCallOptions;pub use core::tracker::TaskOptions;pub use core::tracker::TrackedTask;pub use error::DexcostError;pub use pricing::engine::CostResult;pub use pricing::engine::PricingEngine;pub use pricing::rates::RateEntry;pub use pricing::rates::RateRegistry;pub use pricing::service_catalog::ServiceCatalog;pub use schema::validate::validate;pub use security::redaction::enforce_metadata_limit;pub use security::redaction::hash_value;pub use security::redaction::redact_map;pub use security::redaction::scrub_url;pub use security::redaction::scrub_urls_in_text;pub use transport::buffer::EventBuffer;pub use transport::pusher::EventPusher;pub use clients::tracked_anthropic::TrackedAnthropic;pub use clients::tracked_gemini::TrackedGemini;pub use clients::tracked_openai::TrackedOpenAI;
Modules§
- adapters
- attribution
- Strict attribution-v2 wire contract and durable-record conversion.
- clients
- cloud_
detect - Cloud-environment detection for egress pricing.
- config
- core
- dev_
console - Development mode console output for dexcost.
- error
- integrations
- Integrations with external observability platforms (Langfuse, LangSmith, OTel) and LLM orchestration frameworks (LangChain).
- middleware
- pricing
- scanner
- Code scanner for cost point detection.
- schema
- Schema validation for dexcost Standard Event Schema v1.
- security
- transport
Constants§
- ALL_
SUPPORTED_ INSTRUMENTS - Identifiers for which dedicated tracked client wrappers are shipped.
These are wrapper/instrument names — note that
event.providerfor some wrappers may differ (e.g.TrackedGeminiemits"google"). - VERSION
- SDK version, sourced from
Cargo.toml.
Functions§
- buffer
- Returns the global event buffer (for advanced usage / testing).
- close
- Stops the background pusher and releases resources. Note: Due to OnceLock, the SDK cannot be re-initialized after close().
- flush
- Forces all buffered events to be pushed immediately.
- init
- Initializes the global dexcost SDK. Must be called before
start_task. Safe to call multiple times; only the first call takes effect. - pricing_
engine - Returns the global pricing engine (for advanced usage / testing).
- rate_
registry - Returns the global rate registry (for advanced usage / testing).
- service_
catalog - Returns the global service catalog, or
Nonewhen HTTP tracking is disabled (Config::track_http == false). - start_
task - Starts tracking a new task and returns a
TrackedTask.