Ingest AI Token Usage
POST/api/v1/stats/ai
Ingest AI token consumption records from the Chat Proxy. Records are batched per-user and flushed periodically (every 60 seconds or 100 records, whichever comes first).
All records in a single request must belong to the same user. The user_id in the records must match the authenticated user from the JWT.
Request Body
{
"records": [
{
"user_id": 42,
"usergroup_id": 100,
"input_tokens": 1240,
"output_tokens": 380,
"model": "claude-sonnet-4-20250514",
"tool_calls": 2,
"timestamp": "2026-04-04T10:00:00Z"
}
]
}
Validation
- The JWT must be valid and the
user_idin the records must match the authenticated user. Returns 403 if mismatched. - If
usergroup_iddoesn't match the JWT, the backend uses the group from the JWT (authoritative source). - A batch may contain between 1 and 100 records.
Request
Responses
- 200
- 400
- 401
- 403
- 413
- 429
- 500
Records accepted
Malformed JSON or invalid field values
Invalid or expired JWT
user_id in records does not match JWT identity
More than 100 records in batch
Rate limited
Internal server error