Следите за расходами и балансом
Получайте расходы и остаток баланса организации, чтобы приложение успевало отреагировать до отказа в запросе. Баланс и цены указаны в кредитах. 1 кредит равен 1 суму.
Как это работает
- 01
Вызовите
GET /api/v1/balance, чтобы узнать остаток баланса. - 02
Вызовите
GET /api/v1/usage?days=30, чтобы получить расходы по сервисам и ключам за 7, 30 или 90 дней. - 03
Если запрос получает ответ 402
insufficient_balance, попросите владельца аккаунта пополнить баланс.
Аутентификация
Передавайте ключ как Authorization: Bearer. Обоим эндпоинтам нужно право account:read, и они никогда не оплачиваются.
Пример
Расходы считаются по организации, которой принадлежит ключ запроса. Период состоит из целых дней, включая сегодня.
Справочник API
Поля запросов, ответы, цены и примеры кода для каждого эндпоинта, а также форма, которая отправляет настоящий запрос.
Хранится только в вашем браузере.
Account
Read your own spend, request counts and remaining balance. Free — these endpoints are never billed.
GET /v1/usage
Get usage
Returns spend and request counts for the calling key's organization over the last `days` window (7, 30 or 90; default 30), grouped by service and by API key. Reading usage is free. `period.start` and `period.end` are the counted window: whole days, today included.
Параметры
| Field | Description |
|---|---|
daysquery integer | How many days to count, today included. |
Ответы
| Заголовок | Описание |
|---|---|
X-Request-Idstring | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
X-RateLimit-Limitinteger | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
X-RateLimit-Remaininginteger | How many of them are left this minute. |
| Поле | Описание |
|---|---|
dataОбязательноobject | |
request_idОбязательноstring | format: uuid |
X-Request-Id: string| Поле | Описание |
|---|---|
errorОбязательноobject | |
request_idОбязательноstring | The same ID as the `X-Request-Id` header. format: uuid |
X-Request-Id: string| Поле | Описание |
|---|---|
errorОбязательноobject | |
request_idОбязательноstring | The same ID as the `X-Request-Id` header. format: uuid |
| Заголовок | Описание |
|---|---|
X-Request-Idstring | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
X-RateLimit-Limitinteger | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
X-RateLimit-Remaininginteger | How many of them are left this minute. |
| Поле | Описание |
|---|---|
errorОбязательноobject | |
request_idОбязательноstring | The same ID as the `X-Request-Id` header. format: uuid |
| Заголовок | Описание |
|---|---|
X-Request-Idstring | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
Retry-Afterinteger | Seconds to wait before retrying. |
X-RateLimit-Limitinteger | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
X-RateLimit-Remaininginteger | How many of them are left this minute. |
X-RateLimit-Resetinteger | When the rate limit lets requests through again, as a Unix time in seconds. Sent with a 429 for `rate_limit_exceeded`. |
| Поле | Описание |
|---|---|
errorОбязательноobject | |
request_idОбязательноstring | The same ID as the `X-Request-Id` header. format: uuid |
| Заголовок | Описание |
|---|---|
X-Request-Idstring | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
Retry-Afterinteger | Seconds to wait before retrying. Sent with a 503 during maintenance, when a retry time was set. |
X-RateLimit-Limitinteger | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
X-RateLimit-Remaininginteger | How many of them are left this minute. |
| Поле | Описание |
|---|---|
errorОбязательноobject | |
request_idОбязательноstring | The same ID as the `X-Request-Id` header. format: uuid |
Примеры
Попробовать
Укажите API-ключ в панели выше, чтобы отправлять запросы с ключом.
daysGET /v1/balance
Get balance
Returns the remaining credits for the calling key's organization. Use it to surface a low balance before a request fails with `402`.
Ответы
| Заголовок | Описание |
|---|---|
X-Request-Idstring | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
X-RateLimit-Limitinteger | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
X-RateLimit-Remaininginteger | How many of them are left this minute. |
| Поле | Описание |
|---|---|
dataОбязательноobject | |
request_idОбязательноstring | format: uuid |
X-Request-Id: string| Поле | Описание |
|---|---|
errorОбязательноobject | |
request_idОбязательноstring | The same ID as the `X-Request-Id` header. format: uuid |
X-Request-Id: string| Поле | Описание |
|---|---|
errorОбязательноobject | |
request_idОбязательноstring | The same ID as the `X-Request-Id` header. format: uuid |
| Заголовок | Описание |
|---|---|
X-Request-Idstring | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
Retry-Afterinteger | Seconds to wait before retrying. |
X-RateLimit-Limitinteger | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
X-RateLimit-Remaininginteger | How many of them are left this minute. |
X-RateLimit-Resetinteger | When the rate limit lets requests through again, as a Unix time in seconds. Sent with a 429 for `rate_limit_exceeded`. |
| Поле | Описание |
|---|---|
errorОбязательноobject | |
request_idОбязательноstring | The same ID as the `X-Request-Id` header. format: uuid |
| Заголовок | Описание |
|---|---|
X-Request-Idstring | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
Retry-Afterinteger | Seconds to wait before retrying. Sent with a 503 during maintenance, when a retry time was set. |
X-RateLimit-Limitinteger | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
X-RateLimit-Remaininginteger | How many of them are left this minute. |
| Поле | Описание |
|---|---|
errorОбязательноobject | |
request_idОбязательноstring | The same ID as the `X-Request-Id` header. format: uuid |
Примеры
Попробовать
Укажите API-ключ в панели выше, чтобы отправлять запросы с ключом.