Read the Organization's spend this month against its spend cap
GET /v1/usage/spend
| Property | Value |
|---|---|
| Operation | get_spend_summary |
| Group | Usage |
| Scope | usage:read |
| Route class | read |
| Idempotency | No Idempotency-Key |
| Audit | Not audited: A metadata read; Usage events and the spend counter carry identifiers, units and amounts, never content. |
| Released in | 1.23.0 |
| Phase 0 host | Served (the hosted api pins 1.65.0) |
Answers the Organization's spend counter of the current UTC calendar month, its spend_cap_micros, what remains and the previous month's total (1.23.0, FR-usage-4, FR-dispatch-6). The counter counts live usage only, so every caller reads the same figures whatever the environment of its key. The api reads the counter as admission does and never rates at read time.
Request
Set VOCAL_API to the base URL of your API and VOCAL_API_KEY to an API key with the usage:read scope (Authentication and keys). Replace each placeholder, such as agt_... or <name>, with your own value.
curl "$VOCAL_API/v1/usage/spend" \
-H "Authorization: Bearer $VOCAL_API_KEY"const response = await fetch(`${process.env.VOCAL_API}/v1/usage/spend`, {
headers: {
Authorization: `Bearer ${process.env.VOCAL_API_KEY}`,
},
});
console.log(response.status, await response.text());import os
import requests
response = requests.get(
f"{os.environ['VOCAL_API']}/v1/usage/spend",
headers={
"Authorization": f"Bearer {os.environ['VOCAL_API_KEY']}",
},
)
print(response.status_code, response.text)Responses
| Status | Content type | Shape | Error codes |
|---|---|---|---|
200 | application/json | SpendSummary | |
400 | application/json | ErrorEnvelope | invalid_request |
401 | application/json | ErrorEnvelope | unauthenticated |
403 | application/json | ErrorEnvelope | forbidden |
429 | application/json | ErrorEnvelope | rate_limited |
500 | application/json | ErrorEnvelope | internal_error |
Fields of the 200 answer
The shape is SpendSummary.
| Field | Type | Required | Description |
|---|---|---|---|
object | "spend_summary" | yes | |
period_start | string (date) | yes | The first day of the current UTC calendar month, which the counter covers up to the first day of the next (1.23.0). |
previous_period_spend_micros | integer | yes | The counter of the previous UTC calendar month as it closed, in whole micro-USD (1.23.0); 0 when that month counted nothing. It is the month's spend, not a statement or an invoice. |
remaining_micros | integer or null | yes | The cap less the spend, never below 0; null when there is no cap (1.23.0). At 0 admission refuses new Calls with spend_cap_reached, while Calls in progress continue and are counted at their finalize. |
spend_cap_micros | SpendCapMicros or null | yes | The monthly spend cap the counter is compared with; null when the Organization has none (1.23.0). |
spend_micros | integer | yes | The Organization's spend counter for the current month in whole micro-USD (1.23.0): the rated amounts of the live Usage events written this month, read from the counter as admission reads it; 0 before the month's first finalized live Call. |
updated_at | Timestamp or null | yes | When a finalize last advanced the counter of the current month; null before the month's first finalized live Call (1.23.0). |