Recommended: tracked Anthropic client
Use this when one Anthropic message should become one Margovia run.client.messages.create(request), reads response.usage, records the cost event, and completes or fails the run.
Use a stable, namespaced customerId. Margovia stores this value exactly as sent and uses it as the customer grouping key.
The tracked client records:
provider: "anthropic"- model
- input tokens
- output tokens
- cache creation tokens
- 5 minute and 1 hour cache creation tokens
- cache read tokens
- latency
Alternative: patch an existing client
Use this when you want to keep normal Anthropic call sites and pass Margovia fields through providermetadata.
Custom run input
getRunInput when customer or plan data comes from your authenticated request context instead of provider metadata.
Explicit helper
UsetrackAnthropic(...) when you already have your own helper function around Anthropic calls.
response.usage, records cost, and completes or fails the run.
Use a raw Anthropic client inside trackAnthropic(...). Do not pass an already-wrapped client into this helper or you may double-report the same call.
Common mistake
Do not wrap a raw Anthropic call with.track(...) and expect cost to appear:
margovia.anthropic(client), wrapAnthropic(...), trackAnthropic(...), or run.trackCost(...).