Cost Tracking

Track costs per customer

Track and analyze costs per customer.

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

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

// Track usage with cost
await client.track.trackUsage({
  customerId: 'customer_123',
  eventType: 'model_call',
  model: 'gpt-4',
  provider: 'openai',
  inputTokens: 100,
  outputTokens: 50,
  totalTokens: 150,
  costCents: 25, // Cost in cents
});

// Get cost summary
const summary = await client.usage.summary({
  customerId: 'customer_123',
  startDate: '2024-01-01',
  endDate: '2024-01-31',
});

console.log(`Total cost: $${summary.totalCostCents / 100}`);
import asyncio
from limitry import Client

async def main():
    async with Client(api_key=os.getenv("LIMITRY_API_KEY")) as client:
        # Track usage with cost
        await client.track.track_usage(
            customer_id="customer_123",
            event_type="model_call",
            model="gpt-4",
            provider="openai",
            input_tokens=100,
            output_tokens=50,
            total_tokens=150,
            cost_cents=25,  # Cost in cents
        )

        # Get cost summary
        summary = await client.usage.summary(
            customer_id="customer_123",
            start_date="2024-01-01",
            end_date="2024-01-31",
        )

        print(f"Total cost: ${summary.total_cost_cents / 100}")

asyncio.run(main())