Forecast the month's usage against the spend cap
GET /v1/analytics/forecast
| Property | Value |
|---|---|
| Operation | get_forecast |
| Group | Call trace and analytics |
| Scope | usage:read |
| Route class | read |
| Idempotency | No Idempotency-Key |
| Audit | Not audited: A metadata read; the forecast carries amounts only. |
| Released in | 1.57.0 |
| Phase 0 host | Served (the hosted api pins 1.65.0) |
Forecasts the current UTC month's live usage (1.57.0): month to date plus, per remaining day, the mean of the same weekday over the last four weeks, banded by their lowest and highest, against the Organization's spend cap, with every input. The platform fee is a separate line and not included. The prepaid balance and its date of exhaustion are P2.
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/analytics/forecast" \
-H "Authorization: Bearer $VOCAL_API_KEY"const response = await fetch(`${process.env.VOCAL_API}/v1/analytics/forecast`, {
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/analytics/forecast",
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 | Forecast | |
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 Forecast.
| Field | Type | Required | Description |
|---|---|---|---|
as_of | string | yes | The instant of the latest rollup the forecast read, RFC 3339. |
currency | "USD" | yes | |
days | array of ForecastDay | yes | One input per remaining day, in order. |
estimate | true | yes | Always true: an estimate from list prices and past usage, not a bill. |
exceeds_cap | boolean or null | yes | True when forecast_micros is above the cap; null without a cap. |
forecast_micros | integer | yes | Month to date plus the mean of every remaining day. |
high_micros | integer | yes | Whole micro-USD. |
low_micros | integer | yes | Whole micro-USD. |
month | string | yes | The current UTC month. |
month_to_date_micros | integer | yes | The month's live usage so far. |
object | "forecast" | yes | |
spend_cap_micros | integer or null | yes | The Organization's spend cap; null when it has none. |