MediaGrabber Pro

Metered Usage

Report usage after each chargeable operation and handle limits and credit overage.

If your plugin sells metered capacity (API calls, image generations, translations), report usage after each chargeable operation so limits and billing stay accurate.

Report usage

const usage = await client.reportUsage({
  licenseKey: 'LK-2025-XXXX-YYYY',
  metric: 'api_requests',  // your metric key
  quantity: 1,
})
 
if (!usage.ok || !usage.data.allowed) {
  throw new Error(`Limit reached: ${usage.data?.remaining ?? 0} left this period`)
}

The response tells you where the customer stands:

FieldMeaning
allowedWhether this operation is permitted
remainingUnits left this period
resetAtWhen the counter resets

Check-then-do pattern

Report (and decrement) before doing expensive work, so you never perform an operation the customer can't pay for:

export async function generateImage(prompt: string, licenseKey: string) {
  const usage = await client.reportUsage({
    licenseKey,
    metric: 'image_generations',
    quantity: 1,
    consumeCredits: true, // allow credit overage past the plan limit
  })
 
  if (!usage.ok || !usage.data.allowed) {
    throw new Error(
      `Monthly limit reached. ${usage.data?.remaining ?? 0} left. ` +
      `Resets ${new Date(usage.data?.resetAt ?? '').toLocaleDateString()}.`,
    )
  }
 
  return doGenerateImage(prompt) // only runs if allowed
}

Credit overage

Set consumeCredits: true to let the operation dip into the customer's credit balance once the plan limit is exhausted:

Within plan limit

Usage counts against the monthly cap as normal.

Over the limit, with credits

Credits are deducted and allowed: true is returned.

Over the limit, no credits

allowed: false — show an upgrade/buy-credits prompt.

See Billing & Credits for how credit packs are purchased and tracked.

Choosing metric keys

  • Use stable, lowercase, snake_case keys (api_requests, image_generations).
  • Keep the set small and meaningful — each maps to a limit in your plan config.
  • Don't rename keys after launch; historical usage is bucketed by key.

Next

On this page

Metered Usage | MediaGrabber Pro