Skip to content
Sign Up Free
API Reference

Query API Key quota

Query the used and remaining quota of one BetterToken API Key with Bearer authentication. Convert quota units to money using the returned currency and conversion factor.

Use GET https://bettertoken.ai/api/usage/token/ to query the used and remaining quota of one BetterToken API Key.

Send a request

Use the same sk-... BetterToken API Key that you use for model calls. Set it as the local environment variable BETTERTOKEN_API_KEY before running this command.

Authenticate with Authorization: Bearer <API_KEY>. The request has no parameters or body. Keep the trailing slash; the full URL does not include /v1.

Terminal window
curl -sS 'https://bettertoken.ai/api/usage/token/' \
-H "Authorization: Bearer ${BETTERTOKEN_API_KEY}"

Successful response

code: true indicates a successful query. This response excerpt uses demonstration values.

{
"code": true,
"message": "ok",
"data": {
"object": "token_usage",
"name": "example-key",
"total_granted": 1000000,
"total_used": 250000,
"total_available": 750000,
"unlimited_quota": false,
"quota_currency": "USD"
}
}

Read the quota

FieldMeaning
data.total_availableThe remaining quota of this Key, in internal quota units.
data.total_usedThe cumulative used quota of this Key, in the same units.
data.total_grantedThe sum of used and remaining quota, in the same units.
data.quota_currencyThe currency of the quota, such as USD.
data.unlimited_quotaWhen true, this Key has no separate quota limit. The wallet balance still limits spending.

Convert to money

Read data.quota_per_unit from the response to GET https://bettertoken.ai/api/status. Divide the quota by this factor to get an amount in data.quota_currency.

Remaining amount = data.total_available / data.quota_per_unit

For example, with a conversion factor of 500000, the sample gives 750000 / 500000 = 1.50 USD. Convert used quota in the same way.

To view your account wallet balance, open BetterToken Workspace. This endpoint returns only the quota of the API Key used to authenticate the request.

To view recent requests for this Key, see Query request logs for one API Key.