costhq/extensions module provides drop-in replacements for the official OpenAI, Anthropic, and Google AI SDKs. You swap the constructor, keep every existing call site untouched, and CostHQ automatically logs token counts and costs to your active session — or creates a background session in the dashboard if none is running.
Import
TrackedOpenAI
Replacenew OpenAI(options) with new TrackedOpenAI(options). The resulting object exposes the same chat.completions.create interface as the official openai package.
openai must be installed in your project.
TrackedAnthropic
Replacenew Anthropic(options) with new TrackedAnthropic(options). The resulting object exposes the same messages.create interface as @anthropic-ai/sdk.
@anthropic-ai/sdk must be installed in your project.
TrackedGoogleAI
Pass your API key directly tonew TrackedGoogleAI(apiKey). Call getGenerativeModel exactly as you would with the official GoogleGenerativeAI class.
@google/generative-ai must be installed in your project.
Functional Wrappers
If you already have a configured client instance, thecosthq/wrappers module provides lightweight functional alternatives instead of replacing the constructor:
Background Sessions
If no CostHQ session is currently active when you make an API call through a tracked extension, CostHQ automatically creates a Background API Session in your dashboard. You can view background sessions alongside your CLI-started sessions in the Sessions page. This means you can drop the extensions into any existing Node.js application — a web server, a cron job, a script — and costs appear in your dashboard with zero manual session management.Peer Dependency Requirements
Install whichever SDKs correspond to the extensions you use:These extensions use the same pricing lookup as
cs log-ai. Cost is auto-calculated for all known models. For custom or fine-tuned models not in the built-in pricing table, use the AgentSession API and pass explicit costs via session.logAI(), or register custom pricing with cs pricing set.