Read the Usage events of a Call and their rated total
GET /v1/calls/{call_id}/usage
| Property | Value |
|---|---|
| Operation | get_call_usage |
| 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 every Usage event of the Call with the sum of the rated amounts and the count of unrated events (1.23.0, FR-usage-1). A Call not yet finalized answers no events and a total of 0. A Call of another Organization, or of the other environment for an API key, answers 404 not_found.
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/calls/call_.../usage" \
-H "Authorization: Bearer $VOCAL_API_KEY"const response = await fetch(`${process.env.VOCAL_API}/v1/calls/call_.../usage`, {
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/calls/call_.../usage",
headers={
"Authorization": f"Bearer {os.environ['VOCAL_API_KEY']}",
},
)
print(response.status_code, response.text)Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
call_id | path | CallId | yes | The id of a Call: call_ and the row's UUIDv7 in 26 Crockford base32 characters. Opaque and safe to log. |
Responses
| Status | Content type | Shape | Error codes |
|---|---|---|---|
200 | application/json | CallUsage | |
400 | application/json | ErrorEnvelope | invalid_request |
401 | application/json | ErrorEnvelope | unauthenticated |
403 | application/json | ErrorEnvelope | forbidden |
404 | application/json | ErrorEnvelope | not_found |
429 | application/json | ErrorEnvelope | rate_limited |
500 | application/json | ErrorEnvelope | internal_error |
Fields of the 200 answer
The shape is CallUsage.
| Field | Type | Required | Description |
|---|---|---|---|
amount_micros | integer | yes | The rated total (1.23.0): the sum of amount_micros over the rated events, in whole micro-USD, frozen at finalize; 0 when the Call has no rated event, which includes a Call not yet finalized. |
call_id | CallId | yes | |
environment | Environment | yes | The environment of the Call (1.23.0); a test Call's total is never billed or counted. |
events | array of UsageEvent | yes | Every Usage event of the Call (1.23.0), ordered by stage in the order of CostStage, then by Provider, model and unit; empty until the Call is finalized. |
object | "call_usage" | yes | |
unrated_events | integer | yes | The events the price list had no price for (1.23.0); they are listed and are not in amount_micros, so the total is complete only when this is 0. |