Skip to main content
The 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

Replace new OpenAI(options) with new TrackedOpenAI(options). The resulting object exposes the same chat.completions.create interface as the official openai package.
Peer dependency: openai must be installed in your project.

TrackedAnthropic

Replace new Anthropic(options) with new TrackedAnthropic(options). The resulting object exposes the same messages.create interface as @anthropic-ai/sdk.
Peer dependency: @anthropic-ai/sdk must be installed in your project.

TrackedGoogleAI

Pass your API key directly to new TrackedGoogleAI(apiKey). Call getGenerativeModel exactly as you would with the official GoogleGenerativeAI class.
Peer dependency: @google/generative-ai must be installed in your project.

Functional Wrappers

If you already have a configured client instance, the costhq/wrappers module provides lightweight functional alternatives instead of replacing the constructor:
Use TrackedOpenAI / TrackedAnthropic / TrackedGoogleAI when setting up a new client. Use the trackedGPT / trackedClaude / trackedGemini wrappers when you already have an existing client you cannot replace.

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:
CostHQ does not bundle these SDKs. If the required peer is missing, the constructor throws an informative error at instantiation time.
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.