Skip to Content
Client SDKGet customer usage

Get customer usage

Call getCustomerUsage() to read usage and rate-limit information for the authenticated customer.

const usage = await client.getCustomerUsage()

Read usage allowances

const usage = await client.getCustomerUsage() for (const limit of usage.usageLimits) { console.log({ metric: limit.allowanceMetric, used: limit.rawAmount, allowance: limit.allowanceValue, remaining: limit.remaining, usedPercentage: limit.usedPercentage, scopeKind: limit.scopeKind, scopeValue: limit.scopeValue }) }

Each usage-limit item contains:

FieldTypeDescription
idstringThe usage record ID.
rawAmountnumberThe amount consumed in the current billing period.
allowanceValuenumberThe configured allowance.
allowanceMetricstringThe unit being measured, such as requests, tokens, characters, file bytes, or audio duration.
remainingnumberThe remaining allowance.
usedPercentagenumberThe percentage of the allowance already consumed.
scopeKindstringThe method used to match requests to the rule.
scopeValuestringThe model identifier or pattern attached to the rule.

Read rate-limit rules

The same response contains the customer’s rate-limit rules:

for (const limit of usage.rateLimits) { console.log({ allowance: limit.allowanceValue, metric: limit.allowanceMetric, frequency: limit.rateLimitFrequency, scopeKind: limit.scopeKind, scopeValue: limit.scopeValue }) }

A rate-limit entry describes the configured rule. It does not include the amount consumed within the active rate-limit window.

Get the aggregate percentage

Use getCustomerUsagePercentage() when the interface needs one percentage:

const { percentage } = await client.getCustomerUsagePercentage() renderUsageBar(percentage)

The response is:

type CustomerUsagePercentage = { percentage: number }

Use getCustomerUsage() for a detailed account or billing screen. Use getCustomerUsagePercentage() for a compact progress indicator.