dexcost
Go

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.RecordLLMCall or RecordLiteLLM for gateway-routed calls.
  • HTTP / non-LLM cost capturetask.RecordCost records an explicit non-LLM service fee in exact-precision decimal; task.RecordUsage auto-computes cost from a registered rate; optional TrackHTTP: true in config enables process-wide HTTP cost tracking via the bundled service catalog.
  • Retry trackingtask.MarkRetry tags 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 attributiondexcost.WithCustomer and dexcost.WithProject options on StartTask propagate attribution through the returned context.Context; nested tasks pick up parent_task_id automatically.
  • Local SQLite buffer + background sync — events are written to a local SQLite file (~/.dexcost/dexcost.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 tracker.Pricing().SetCustomPricing; non-LLM service rates are registered via tracker.Rates().Register.

Requirements

Go 1.21 or later.

Next steps

  • Installationgo get github.com/DexwoxBusiness/dexcost-go and module details.
  • 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, StartTask, Wrap*, RecordLLMCall, RecordCost, Flush, Close, and more.

On this page