SDK Reference
Attribution Tags
Tags are the core attribution mechanism in Kostrack — every API call carries a dict of key-value pairs you define.
Setting tags on the client
Tags set on the client apply to every call made with that client:
client = Anthropic(tags={
"project": "openmanagr",
"feature": "invoice-extraction",
"team": "engineering",
"environment": "production",
"user_id": "user_123",
})
Per-call overrides
Override or add tags for a specific call using kostrack_tags:
client.messages.create(
model="claude-sonnet-4-6",
max_tokens=512,
messages=[...],
kostrack_tags={
"feature": "different-feature",
"ab_test": "variant-b",
}
)
Reserved keys
These keys appear as dropdown variables in the Grafana Overview dashboard:
| Key | Example | Grafana panel |
|---|---|---|
project | openmanagr | Project filter dropdown |
feature | invoice-extraction | Attribution dashboard |
team | engineering | Team spend breakdown |
environment | production | Env filter dropdown |
user_id | user_123 | Per-user cost tracking |
Custom keys
Any key beyond the reserved set is stored in the JSONB tags column and GIN-indexed for fast queries:
-- Spend by A/B test variant
SELECT tags->>'ab_test' AS variant, SUM(cost_usd)
FROM llm_calls
WHERE tags ? 'ab_test'
GROUP BY 1;