Run
A run is one AI workflow execution. Examples:support_replycontract_summarygenerate_report
running: the run has started but has not reported a terminal statecompleted: the workflow finished successfullyfailed: the workflow failed or was cancelled
margovia.openai(client), margovia.anthropic(client), wrapOpenAI(..., { autoTrack: true }), wrapAnthropic(..., { autoTrack: true }), trackOpenAI(...), or trackAnthropic(...), the SDK handles this lifecycle and records provider cost for you.
If you use margovia.track(...), the SDK handles the run lifecycle, but cost is recorded only when the code inside uses wrapped provider clients or manually calls run.trackCost(...).
If you use startRun(...) manually, always call run.complete(...) or run.fail(...).
Cost event
A cost event records the money spent inside a run. Usually this is one model provider call, tool call, or manually priced operation. Cost events can include:- Provider and model
- Input and output tokens
- Cached input tokens
- Cache creation tokens
- Reasoning tokens
- Manual
costUsd - Latency and status
margovia.openai(client) or margovia.anthropic(client) so cost events are recorded automatically.
Outcome
An outcome records what the run produced or what business value it created. Examples:reply_generatedsummary_createdlead_qualifiedreport_exported
Customer attribution
Margovia works best when every AI workflow includes customer and plan context:customerId should be your stable join key back to your app or billing system. Margovia does not rewrite this value.
Good IDs are namespaced and stable:
"1" when possible. If your internal ID is numeric, prefix it before sending, such as workspace_1.