Overview
The Go SDK brings Agent Unit Economics to Go services by wrapping LLM clients and recording costs with full customer, project, and task attribution.
The dexcost Go SDK brings Agent Unit Economics to Go services. Because Go cannot monkey-patch at runtime, the integration model is wrapper clients: you pass your existing LLM client to WrapOpenAI, WrapAnthropic, WrapGemini, WrapBedrock, WrapCohere, or WrapGroq, and the wrapper records every call automatically. For providers without a Go SDK — or when you call an LLM through a gateway — you can also record calls explicitly with task.RecordLLMCall. 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. Requires Go 1.21+.
Key capabilities
- LLM cost capture — wrapper clients for OpenAI, Anthropic, Google Gemini, AWS Bedrock, Cohere, and Groq record provider, model, input/output tokens, latency, and computed cost for every call inside a tracked task. Use
task.RecordLLMCallorRecordLiteLLMfor gateway-routed calls. - HTTP / non-LLM cost capture —
task.RecordCostrecords an explicit non-LLM service fee in exact-precision decimal;task.RecordUsageauto-computes cost from a registered rate; optionalTrackHTTP: truein config enables process-wide HTTP cost tracking via the bundled service catalog. - Retry tracking —
task.MarkRetrytags a retry event with a reason string; the optional retry heuristic engine can detect retries automatically by inspecting recent LLM call patterns. - Customer / project / task attribution —
dexcost.WithCustomeranddexcost.WithProjectoptions onStartTaskpropagate attribution through the returnedcontext.Context; nested tasks pick upparent_task_idautomatically. - Local SQLite buffer + background sync — events are written to a local SQLite file (
~/.dexcost/dexcost.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
tracker.Pricing().SetCustomPricing; non-LLM service rates are registered viatracker.Rates().Register.
Requirements
Go 1.21 or later.
Next steps
- Installation —
go get github.com/DexwoxBusiness/dexcost-goand module details. - 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,StartTask,Wrap*,RecordLLMCall,RecordCost,Flush,Close, and more.