Quickstart
Get from zero to your first metered API call in under 5 minutes.
Prerequisites
- An Aforo account (sign up at www.aforo.ai/auth/sign-in)
- Your Aforo API key from Settings → API Keys
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
- Go to Pricing Studio → Rate Cards
- Click + New Rate Card
- Select your product and the
api-callsbillable unit - Choose a pricing model (e.g. Per Unit at $0.001 per call)
- 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
- Products → — model your API as a monetizable product
- Billable Units → — define what you charge for
- Rate Plans → — configure pricing models (graduated, volume, flat rate)
- Customers → — manage customer accounts and agents
- Try API → — interactive API explorer; logged-in visitors see their real key inlined automatically