These requests do not use your chat rate limits. They do not cost credits.
Get the balance
GET/balance
Money values are strings in US dollars with 6 decimal places. Read them with a decimal type, not a float.
The values are for the whole account (
scope: "account"). The key object shows which key made the request. Its spend values are null for now.
Get usage
GET/usage
Each row gives
requests, input_tokens, cached_input_tokens, output_tokens, and cost. Cached input tokens are part of input_tokens. Days without usage do not have a row.
A response contains 90 days or fewer. When more days are available, next_page gives the first day of the next page. When next_page is null, you have all the data.
Usage history starts at history_start. Pages before that date are empty.
Each cost is rounded on its own. The sum of the rows can differ from total.cost in the last digit.
The response has an ETag header. Send it back in If-None-Match. If nothing in the response changed, including as_of, the API returns HTTP 304 without a body. as_of moves forward about every 10 seconds, so the ETag changes at least that often.
Freshness
- The API reads the balance again after 5 seconds or more.
- A request shows in usage after its charges are final. This is usually within 15 seconds after the request ends.
- Usage and cost go on the UTC day when the request started.
as_oftells you when the data was last updated.
Rate limits
Each key can send 20 requests each minute to each endpoint, with a burst of 5. Responses to requests with a valid key have these headers. A 503 may not have them.
If you send too many requests, the API returns HTTP 429 with a
Retry-After header. Wait that number of seconds before you try again. To show a balance in an app, request it one time each minute or less.
Errors
An error response haserror.message, error.type, and error.code. A 400 also names the parameter in error.param.