Sign in →

Quickstart

Get from zero to your first metered API call in under 5 minutes.

Prerequisites

Step 1 — Install the SDK

    npm install @aforo/metering
    

    Step 2 — Initialize the Client

    import { AforoClient } from '@aforo/metering'
    
    const aforo = new AforoClient({
      tenantId: 'your-tenant-id',
      apiKey: process.env.AFORO_API_KEY,  // never hardcode
      productId: 'your-product-id',
    })
    

    Never expose your API key client-side. Always read it from an environment variable on your server.

    Step 3 — Record a Usage Event

    await aforo.ingest({
      customerId: 'cust_abc123',
      metricId: 'api-calls',
      quantity: 1,
      timestamp: new Date().toISOString(),
      properties: {
        endpoint: '/v1/translate',
        model: 'gpt-4o',
      },
    })
    

    Step 4 — Verify Ingestion

    Open Intelligence → Event Log in your Aforo dashboard. You should see your event within 5 seconds.

    Events arriving more than 24 hours in the past are flagged as late arrivals but still processed. Events older than 90 days are rejected.

    Step 5 — Set Up a Rate Plan

    1. Go to Pricing Studio → Rate Cards
    2. Click + New Rate Card
    3. Select your product and the api-calls billable unit
    4. Choose a pricing model (e.g. Per Unit at $0.001 per call)
    5. Click Publish

    Step 6 — Subscribe a Customer

    curl -X POST https://pricing.aforo.ai/api/v1/subscriptions \
      -H "Authorization: Bearer $AFORO_API_KEY" \
      -H "X-Tenant-Id: $TENANT_ID" \
      -H "Content-Type: application/json" \
      -d '{
        "customerId": "cust_abc123",
        "offeringId": "off_starter_monthly",
        "billingMode": "POSTPAID"
      }'
    

    What's Next