Returns the authenticated developer's most-called API endpoints ranked by call volume within a requested time window. Useful for identifying hot endpoints, spotting usage spikes, and optimizing spend.
GET /api/usage/by-endpoint
Authorization: Bearer <token>
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
from |
string | No | 30 days ago | Start of period (ISO-8601, e.g. 2026-06-25T00:00:00Z) |
to |
string | No | Now | End of period (ISO-8601) |
limit |
integer | No | 5 |
Maximum number of endpoints to return (≥ 1) |
apiId |
string | No | all APIs | Filter results to a specific registered API |
- If
fromandtoare both omitted the last 30 days are used. frommust be ≤to; otherwise a400is returned.limitmust be a positive integer; otherwise a400is returned.
HTTP 200:
{
"data": [
{ "endpoint": "/v1/weather/current", "calls": 142, "revenue": "142000" },
{ "endpoint": "/v1/weather/forecast", "calls": 87, "revenue": "87000" }
],
"period": {
"from": "2026-06-25T00:00:00.000Z",
"to": "2026-07-25T00:00:00.000Z"
}
}| Field | Type | Description |
|---|---|---|
data |
array | Endpoints ordered by calls descending; ties broken by path ascending. |
data[].endpoint |
string | Endpoint path identifier (e.g. /v1/weather/current). |
data[].calls |
integer | Total call count in the period. |
data[].revenue |
string | Total revenue in smallest USDC units (string to avoid precision loss). |
period.from |
string | Effective start of the query window (ISO-8601). |
period.to |
string | Effective end of the query window (ISO-8601). |
| HTTP status | Code | When |
|---|---|---|
400 |
BAD_REQUEST |
Invalid date, from > to, or invalid limit. |
401 |
UNAUTHORIZED |
Missing or invalid bearer token. |
500 |
INTERNAL_ERROR |
Unexpected server error. |
See docs/error-codes.md for the full error envelope format.
Requires a valid developer bearer token (Authorization: Bearer <token>) or x-user-id header in local/test flows. Results are always scoped to the authenticated developer — cross-developer data is never returned.
- In-memory store (
InMemoryUsageEventsRepository): groups events byendpoint, sums calls and revenue, then sorts by calls descending (ties broken by path ascending) before slicing tolimit. - PostgreSQL store (
PgUsageEventsRepository): issues a singleGROUP BY endpoint_id ORDER BY calls DESCquery with a parameterisedLIMIT, running entirely within the database for efficiency. - The route is mounted at
/api/usage/by-endpointbefore the generic/api/usagemount so the more-specific path always matches first. - The standard REST rate limiter applies to this route (configurable via
REST_RATE_LIMIT_WINDOW_MS/REST_RATE_LIMIT_MAX_REQUESTS).
async function getTopEndpoints(token: string, limit: number = 3): Promise<void> {
const to = new Date();
const from = new Date();
from.setDate(to.getDate() - 7); // Last 7 days
const url = new URL('https://api.callora.io/api/usage/by-endpoint');
url.searchParams.append('limit', limit.toString());
url.searchParams.append('from', from.toISOString());
url.searchParams.append('to', to.toISOString());
const response = await fetch(url.toString(), {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
console.log(JSON.stringify(data, null, 2));
}$Token = "YOUR_BEARER_TOKEN"
$To = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$From = (Get-Date).AddDays(-7).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$Url = "https://api.callora.io/api/usage/by-endpoint?limit=3&from=$From&to=$To"
Invoke-RestMethod -Uri $Url -Method Get -Headers @{ Authorization = "Bearer $Token" }curl -s \
-H "Authorization: Bearer $TOKEN" \
"https://api.callora.io/api/usage/by-endpoint?limit=3&from=$(date -u -d '-7 days' +%Y-%m-%dT%H:%M:%SZ)"