Skip to main content

Introduction

Starleads bills your usage in credits. Every billing period comes with a pool of included credits; each voice call, SMS or other billable action draws it down. When the pool runs low your agents stop working, so you want to know before it happens — not after. This guide shows you how to build a complete balance-monitoring loop on top of the public API using a single API key:
  1. Read your current balance with GET /Consumption.
  2. Decide whether to alert based on the remaining credits, the usage percentage, and the subscription status.
  3. When usage is high, drill down with GET /Consumption/breakdown to see which channels, months and agents consumed the credits.
Everything below relies only on your API key passed in the X-Api-Key header. The company is derived from the key — you never pass a company identifier. Figures are reported as-is: a negative remaining balance or a usage above 100% is published verbatim, so your monitoring can react to overage instead of seeing a clamped 0.
These billing endpoints expose company-wide data (balance, breakdown, contract and ledger). Any holder of your API key can read them. See the Authentication guide before sharing keys.

Getting Started

Read the current balance

Call GET /Consumption to get the balance for the current billing period. The response tells you how many credits were included, how many were consumed, how many remain, and when the period ends — the end date is when your credits recharge.Read these fields:
If the company has no active subscription, this endpoint returns 404, not a zeroed balance. Treat 404 as “no subscription to monitor”, not as “zero credits left”.
Endpoint: GET /Consumption

Decide whether to alert

With the balance in hand, apply your own alerting rules. A robust monitor checks three things, in order:
  1. Status first. If status is not Active (e.g. PastDue, Paused, Cancelled), alert regardless of the numbers — billing may already be interrupted.
  2. Threshold on the balance. Alert when remainingCredits drops below a floor you choose (for example 500 credits), or when usagePercent crosses a ceiling (for example 80%). Use whichever expresses your budget best; usagePercent is convenient because it is normalised across plans.
  3. Overage. A negative remainingCredits (or usagePercent > 100) means you are already over the included pool. Escalate this separately from a simple “running low” warning.
Because periodEnd is the recharge date, you can also tell the difference between “low but the period resets tomorrow” and “low with two weeks to go”.No new endpoint here — this step is pure logic on the response from step 1.

Drill into the breakdown

When an alert fires (or on a schedule, e.g. weekly), call GET /Consumption/breakdown over a date range to understand where the credits went. The response splits the total three ways — by channel, by month, and by agent (each agent with its own per-campaign breakdown).The range is passed as from and to query parameters (both inclusive, UTC). It is mandatory, must be ordered (to after from), and may span at most 366 days. A range with no consumption returns a total of 0, not an error.Each of the three axes sums exactly to totalCredits. If the upstream total ever exceeds the sum of the itemised entries, a residual entry is added on each axis so nothing disappears: channel "unattributed", month "unattributed", or an agent with agentId: null and nameStatus: "Unattributed". A deleted agent is still reported, with nameStatus: "Deleted", so its credits are never silently dropped.Read these fields:Endpoint: GET /Consumption/breakdown?from=...&to=...

Code Examples

The examples below assemble the three steps into one runnable monitor. Set THRESHOLD_CREDITS and THRESHOLD_PERCENT to match your budget.

Read the current balance

Decide whether to alert

Drill into the breakdown

Putting it together

Run monitor() on a schedule (e.g. every hour via cron). GET /Consumption is rate-limited to 30 requests per minute and GET /Consumption/breakdown to 10 per minute, which is ample for periodic monitoring.

Going Further

  • Audit the ledger. To see the individual credit movements behind the totals — one line per debit, credit, adjustment or refund — use GET /Consumption/transactions. It is paginated with the standard pageNumber / pageSize convention.
  • Inspect your plan and limits. GET /Subscription returns your plan name, subscription status, active features and effective limits, so a monitor can also flag when you are close to a contractual limit. No pricing information is exposed.

API Reference

Explore all consumption and subscription endpoints:

Current consumption

Read the credit balance for the current billing period.

Consumption breakdown

Split consumption by channel, month and agent over a date range.

Consumption transactions

List the individual credit ledger entries, paginated.

Subscription contract

Read your plan, status, active features and effective limits.