Read your quota off a response
Every response is metered and stamped with X-Quota-Limit / X-Quota-Used / X-Quota-Remaining. The SDK parses them into a Quota on every list page, so you can watch your monthly budget without a second request.
1.List a page and read its quota
The quota is null only when the server omitted the headers (never on a normal list response).
const page = await api.nba.teams.list({ limit: 3 })
if (page.quota) {
console.log(`quota: ${page.quota.remaining} of ${page.quota.limit} records left this month`)
} else {
console.log('no quota headers on this response')
}The complete program
Every step as one runnable file. It reads STAT_API_KEY from the environment, and is the same file that ships in the cookbook project for each SDK.
import { StatApi } from '@stat-api/client'
const api = new StatApi() // reads STAT_API_KEY from the environment
// List a page and read its quota
const page = await api.nba.teams.list({ limit: 3 })
if (page.quota) {
console.log(`quota: ${page.quota.remaining} of ${page.quota.limit} records left this month`)
} else {
console.log('no quota headers on this response')
}