1
Install the SDK
Install Margovia in the backend app that calls OpenAI, Anthropic, or another model provider.Install the provider SDK you use too:
2
Set your API keys
Add the Margovia key to the same backend process that calls your model provider.Installing the SDK alone sends nothing. When
MARGOVIA_API_KEY is configured, the SDK sends events to Margovia Cloud by default.If you self-host Margovia, run a compatible receiver, or test against a local API, set MARGOVIA_BASE_URL:3
Track an OpenAI call
Create a tracked OpenAI client once, then pass Margovia fields beside the real OpenAI request.The tracked client still calls OpenAI. Margovia records the workflow name, customer, token usage, and cost.
4
Or track an Anthropic call
For Anthropic, install the Anthropic SDK instead:
5
Verify tracking
Trigger the AI feature you instrumented. For example, submit a support ticket, generate a report, score a tweet, or run the backend route that contains the tracked provider call.Then open Margovia and look for the workflow name you sent:You can also trigger the backend route directly with your usual local tool, such as curl, Postman, a queued job runner, or your app’s test console. The important part is that the code path containing the tracked provider call runs once.If no API key is configured, the SDK skips Margovia tracking and does not send events.If you do not see a run, check:
- The code ran on your backend, not in the browser
MARGOVIA_API_KEYis set in the same process that calls OpenAI or Anthropic- The API key belongs to the Margovia project you are viewing
MARGOVIA_BASE_URLis not pointing at a local API by accident
If you already have a helper
UsetrackAnthropic(...) or trackOpenAI(...) only when you already have your own provider helper function and want to keep that shape.
startRun, run.trackCost, and run.complete.
Use a raw provider client inside trackAnthropic(...) or trackOpenAI(...). Do not pass an already-wrapped client into these helpers or you may double-report cost.
What .track(...) is for
margovia.track(...) tracks a workflow boundary. It does not read OpenAI or Anthropic token usage by itself.
Good use:
anthropic is not wrapped then Margovia receives no token usage and no cost.
If you use another provider
OpenAI and Anthropic have first-class helpers because the SDK knows how to read their usage fields. For Gemini, Cohere, custom models, search APIs, or internal tools, use manual tracking and send either tokens orcostUsd.
Attribution checklist
Send attribution from your app’s source of truth:customerId: stable account, workspace, org, tenant, or billing customer IDcustomerName: readable display namecustomerPlan: current plan name and monthly revenueuserId: optional actor inside that customer account
workspace_123, org_abc, or stripe_cus_123. Margovia stores the ID exactly as sent so it can join back to your app and billing data.