dexcost
TypeScript

Overview

The dexcost TypeScript SDK brings Agent Unit Economics to Node.js, auto-instrumenting 6 LLM providers and the global fetch API at runtime.

The dexcost TypeScript SDK brings Agent Unit Economics to Node.js. It auto-instruments 6 LLM providers and the global fetch API at runtime, attributing every LLM call, non-LLM service fee, and retry to a customer, project, and task — no changes to existing call sites required.

Key capabilities

  • LLM cost capture — auto-patches OpenAI, Anthropic, Vercel AI, Google Gemini, AWS Bedrock, and Cohere; records provider, model, input/output tokens, latency, and computed cost for every call inside a tracked task. Model Context Protocol (MCP) tool calls are instrumented as well.
  • HTTP / non-LLM cost capture — patches globalThis.fetch to capture HTTP calls to domains in the bundled 163-service catalog covering Pinecone, Stripe, Twilio, SendGrid, Firecrawl, Exa Search, and more.
  • Retry tracking — detects and flags retry events, accumulates retry-waste cost, and attributes each retry to a root cause (rate limit, timeout, 5xx).
  • Customer / project / task attributiontrack() and setContext() propagate customerId, projectId, and optional metadata through AsyncLocalStorage across await points and concurrent operations automatically.
  • Local SQLite buffer + background sync — events are written to a local SQLite file first; a background pusher flushes them to the Control Layer in configurable batches, so data is never lost on a crash.
  • Pricing engine — bundled model pricing is available offline and refreshes from the Control Layer in the background; custom per-model rates can be registered at any time.

Requirements

Node.js 18 or later.

Next steps

  • Installationnpm install dexcost and optional provider peer dependencies.
  • Quickstart — one-line initialization and your first tracked call.
  • Instrumentation — LLM provider details, HTTP tracking, and controlling what gets patched.
  • Configuration — all init() parameters, environment variables, and privacy options.
  • API Reference — full public API: init, track, setContext, flush, close, and more.

On this page