Constructor
Options
MARGOVIA_API_KEYMARGOVIA_BASE_URLMARGOVIA_DEBUG
MARGOVIA_API_KEY, the client skips Margovia tracking. With MARGOVIA_API_KEY, it sends to Margovia Cloud unless baseUrl or MARGOVIA_BASE_URL points at a self-hosted or compatible receiver.
openai
client.chat.completions.create(request), records cost from the response usage, and completes or fails the run.
Use this for the simplest one-call OpenAI integration.
anthropic
client.messages.create(request), records cost from the response usage, and completes or fails the run.
Use this for the simplest one-call Anthropic integration.
wrapOpenAI
client.chat.completions.create.
With autoTrack: true, the wrapper starts a run, records the provider cost event, and completes the run after the provider call succeeds.
wrapAnthropic
client.messages.create.
With autoTrack: true, the wrapper starts a run, records the provider cost event, and completes the run after the provider call succeeds.
trackOpenAI
trackAnthropic
track
track does not extract provider token usage by itself. Use tracked or wrapped provider clients inside fn, call trackOpenAI(...) or trackAnthropic(...), or manually report cost.
canRun
flush
flush is useful before a short-lived process exits.
startRun
MargoviaRun.
Manual runs stay running until run.complete(...) or run.fail(...) is called.
trackCost
completeRun: true is explicitly sent. In normal manual workflows, call run.complete(...) after all work is finished.
trackOutcome
Helpers
customer(...) and user(...) help create stable namespaced IDs such as workspace_123 and user_456.