Skip to main content
Usage queries have two authentication modes. Usage logs and summary endpoints use a signed-in session or management access credential. The current API key usage endpoint uses the sk- API key itself.

Query usage logs

GET /api/log/self?p=1&page_size=20
p
integer
Page number, starting from 1.
page_size
integer
Number of records per page.
type
integer
Filter by log type.
token_name
string
Filter by API key name.
model_name
string
Filter by model name.
group
string
Filter by group.
request_id
string
Filter by request ID.
start_timestamp
integer
Start time as a Unix timestamp.
end_timestamp
integer
End time as a Unix timestamp.
The response includes your usage records, such as model, API key, group, token usage, cost, and call status.

Query usage summary

GET /api/log/self/stat?start_timestamp=1700000000&end_timestamp=1700100000
Returns usage summary fields for the selected time range, such as quota, rpm, and tpm. For reconciliation, rely on console usage logs and balance changes.

Query current API key usage

curl https://api.aiohub.org/api/usage/token \
  -H "Authorization: Bearer sk-your-api-key"
This endpoint returns the usage summary for the current sk- API key. It is not the signed-in user’s all-API-key list endpoint. By default, the data field returns the current API key quota status:
{
  "success": true,
  "message": "ok",
  "data": {
    "total_granted": 2,
    "total_used": 0.5,
    "total_available": 1.5,
    "unlimited_quota": false,
    "expires_at": 0
  }
}
total_granted, total_used, and total_available reflect the site’s current quota display units. The response does not include a unit or symbol. expires_at is a Unix-second timestamp; 0 means no expiry is set.

Query current API key usage for a time range

curl "https://api.aiohub.org/api/usage/token?start_timestamp=1700000000&end_timestamp=1700100000" \
  -H "Authorization: Bearer sk-your-api-key"
The same endpoint accepts start_timestamp and end_timestamp for a time-range summary. Use it for scripts that only have an API key and do not have a signed-in session or management access credential. It summarizes only the current API key’s own quota consumption and does not return log details.
start_timestamp
integer
required
Start time as a Unix-second timestamp. The range includes this second. Send it together with end_timestamp; do not send millisecond timestamps.
end_timestamp
integer
required
End time as a Unix-second timestamp. The range includes this second. Send it together with start_timestamp; end_timestamp must be greater than or equal to start_timestamp.
When a valid range is requested, data includes range_used:
{
  "success": true,
  "message": "ok",
  "data": {
    "total_granted": 2,
    "total_used": 0.5,
    "range_used": 0.12,
    "total_available": 1.5,
    "unlimited_quota": false,
    "expires_at": 0
  }
}
range_used uses the same site quota display setting and is rounded to 6 decimal places. Ranges with no usage return a successful response with range_used: 0. Other query parameters are ignored. Disabled or expired API keys cannot query this endpoint; exhausted API keys can still query their own historical summary.

Troubleshooting

  • If a record is missing, check the time range and page number first.
  • Cross-filter by API key name, model, group, and time window.
  • If an automation script only has an API key, use /api/usage/token for the current API key summary and add start_timestamp / end_timestamp for time-range usage.
  • Costs and token counts follow the console usage logs.