Multi-Tenant Tracking

Track usage across multiple tenants

Track usage for multiple tenants in a SaaS application.

import { Client } from '@limitry/sdk';

const client = new Client({
  apiKey: process.env.LIMITRY_API_KEY!,
});

async function trackTenantUsage(tenantId: string, userId: string, usage: any) {
  // Use tenant ID as customer ID
  await client.track.trackUsage({
    customerId: `tenant_${tenantId}`,
    eventType: 'model_call',
    properties: {
      tenant_id: tenantId,
      user_id: userId,
    },
    ...usage,
  });
}

// Get usage for a tenant
async function getTenantUsage(tenantId: string) {
  return await client.usage.summary({
    customerId: `tenant_${tenantId}`,
    startDate: '2024-01-01',
    endDate: '2024-01-31',
  });
}
import asyncio
from limitry import Client

async def track_tenant_usage(tenant_id: str, user_id: str, usage: dict):
    async with Client(api_key=os.getenv("LIMITRY_API_KEY")) as client:
        await client.track.track_usage(
            customer_id=f"tenant_{tenant_id}",
            event_type="model_call",
            properties={
                "tenant_id": tenant_id,
                "user_id": user_id,
            },
            **usage,
        )

async def get_tenant_usage(tenant_id: str):
    async with Client(api_key=os.getenv("LIMITRY_API_KEY")) as client:
        return await client.usage.summary(
            customer_id=f"tenant_{tenant_id}",
            start_date="2024-01-01",
            end_date="2024-01-31",
        )