feat(usage): add per-call token usage records table

Expose a paginated endpoint and UI table that lists individual LLM call
records (assistant messages with usage) per bot, showing time, session
type, model, provider, and token counts. Respects existing date / model
/ session-type filters and adds full-height loaders plus a max-width
layout to keep the usage page consistent with other top-level pages.
This commit is contained in:
Acbox
2026-04-24 15:05:53 +08:00
parent 419867655e
commit 8136ef6ed6
13 changed files with 1138 additions and 15 deletions
+97
View File
@@ -2016,6 +2016,44 @@ definitions:
type: string
type: array
type: object
handlers.TokenUsageRecord:
properties:
cache_read_tokens:
type: integer
cache_write_tokens:
type: integer
created_at:
type: string
id:
type: string
input_tokens:
type: integer
model_id:
type: string
model_name:
type: string
model_slug:
type: string
output_tokens:
type: integer
provider_name:
type: string
reasoning_tokens:
type: integer
session_id:
type: string
session_type:
type: string
type: object
handlers.TokenUsageRecordsResponse:
properties:
items:
items:
$ref: '#/definitions/handlers.TokenUsageRecord'
type: array
total:
type: integer
type: object
handlers.TokenUsageResponse:
properties:
by_model:
@@ -6232,6 +6270,65 @@ paths:
summary: Get token usage statistics
tags:
- token-usage
/bots/{bot_id}/token-usage/records:
get:
description: Paginated list of individual LLM call records (assistant messages
with usage) for a bot, with optional model and session type filters
parameters:
- description: Bot ID
in: path
name: bot_id
required: true
type: string
- description: Start date (YYYY-MM-DD)
in: query
name: from
required: true
type: string
- description: End date exclusive (YYYY-MM-DD)
in: query
name: to
required: true
type: string
- description: Optional model UUID to filter by
in: query
name: model_id
type: string
- description: 'Optional session type: chat, heartbeat, or schedule'
in: query
name: session_type
type: string
- description: Page size (default 20, max 100)
in: query
name: limit
type: integer
- default: 0
description: Offset
in: query
name: offset
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/handlers.TokenUsageRecordsResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/handlers.ErrorResponse'
"403":
description: Forbidden
schema:
$ref: '#/definitions/handlers.ErrorResponse'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/handlers.ErrorResponse'
summary: List per-call token usage records
tags:
- token-usage
/bots/{bot_id}/tools:
post:
description: MCP endpoint for tool discovery and invocation.