Skip to main content

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_id in the records must match the authenticated user. Returns 403 if mismatched.
  • If usergroup_id doesn'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

Records accepted