Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
479 changes: 478 additions & 1 deletion backend/docs/docs.go

Large diffs are not rendered by default.

481 changes: 479 additions & 2 deletions backend/docs/swagger.json

Large diffs are not rendered by default.

311 changes: 310 additions & 1 deletion backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,161 @@ definitions:
username:
type: string
type: object
internal_transport_http_admin.UsageStatisticsMetricsResponse:
properties:
avgLatencyMS:
type: integer
billedNanousd:
type: integer
billedUSD:
type: number
cacheReadTokens:
type: integer
cacheWriteTokens:
type: integer
callCount:
type: integer
inputTokens:
type: integer
outputTokens:
type: integer
reasoningTokens:
type: integer
recordCount:
type: integer
totalTokens:
type: integer
type: object
internal_transport_http_admin.UsageStatisticsModelRankResponse:
properties:
avgLatencyMS:
type: integer
billedNanousd:
type: integer
billedUSD:
type: number
cacheReadTokens:
type: integer
cacheWriteTokens:
type: integer
callCount:
type: integer
inputTokens:
type: integer
outputTokens:
type: integer
platformModelName:
type: string
reasoningTokens:
type: integer
recordCount:
type: integer
totalTokens:
type: integer
trend:
items:
$ref: '#/definitions/internal_transport_http_admin.UsageStatisticsTrendResponse'
type: array
type: object
internal_transport_http_admin.UsageStatisticsResponse:
properties:
range:
properties:
endDate:
type: string
granularity:
type: string
startDate:
type: string
type: object
section:
type: string
topModels:
items:
$ref: '#/definitions/internal_transport_http_admin.UsageStatisticsModelRankResponse'
type: array
topUsers:
items:
$ref: '#/definitions/internal_transport_http_admin.UsageStatisticsUserRankResponse'
type: array
totals:
$ref: '#/definitions/internal_transport_http_admin.UsageStatisticsMetricsResponse'
trend:
items:
$ref: '#/definitions/internal_transport_http_admin.UsageStatisticsTrendResponse'
type: array
type: object
internal_transport_http_admin.UsageStatisticsResponseDoc:
properties:
data:
$ref: '#/definitions/internal_transport_http_admin.UsageStatisticsResponse'
errorMsg:
type: string
type: object
internal_transport_http_admin.UsageStatisticsTrendResponse:
properties:
avgLatencyMS:
type: integer
billedNanousd:
type: integer
billedUSD:
type: number
cacheReadTokens:
type: integer
cacheWriteTokens:
type: integer
callCount:
type: integer
inputTokens:
type: integer
outputTokens:
type: integer
periodStart:
type: string
reasoningTokens:
type: integer
recordCount:
type: integer
totalTokens:
type: integer
type: object
internal_transport_http_admin.UsageStatisticsUserRankResponse:
properties:
avgLatencyMS:
type: integer
billedNanousd:
type: integer
billedUSD:
type: number
cacheReadTokens:
type: integer
cacheWriteTokens:
type: integer
callCount:
type: integer
inputTokens:
type: integer
outputTokens:
type: integer
reasoningTokens:
type: integer
recordCount:
type: integer
totalTokens:
type: integer
trend:
items:
$ref: '#/definitions/internal_transport_http_admin.UsageStatisticsTrendResponse'
type: array
userDisplayName:
type: string
userID:
type: integer
userLabel:
type: string
username:
type: string
type: object
internal_transport_http_admin.UserAuthEventListResponseDoc:
properties:
data:
Expand Down Expand Up @@ -2120,6 +2275,48 @@ definitions:
unit:
type: string
type: object
internal_transport_http_billing.OpenRouterOfficialPricingDataResponse:
properties:
cached:
type: boolean
fetchedAt:
type: string
items:
items:
$ref: '#/definitions/internal_transport_http_billing.OpenRouterOfficialPricingItemResponse'
type: array
stale:
type: boolean
type: object
internal_transport_http_billing.OpenRouterOfficialPricingItemResponse:
properties:
canonicalSlug:
type: string
id:
type: string
name:
type: string
pricing:
$ref: '#/definitions/internal_transport_http_billing.OpenRouterOfficialPricingUnitPricingResponse'
type: object
internal_transport_http_billing.OpenRouterOfficialPricingResponseDoc:
properties:
data:
$ref: '#/definitions/internal_transport_http_billing.OpenRouterOfficialPricingDataResponse'
errorMsg:
type: string
type: object
internal_transport_http_billing.OpenRouterOfficialPricingUnitPricingResponse:
properties:
completion:
type: string
inputCacheRead:
type: string
inputCacheWrite:
type: string
prompt:
type: string
type: object
internal_transport_http_billing.PatchRedemptionCodeRequestDoc:
properties:
description:
Expand Down Expand Up @@ -3031,6 +3228,7 @@ definitions:
- chat
- image_generation
- image_edit
- video_generation
type: string
type: object
internal_transport_http_channel.ModelProbeResponse:
Expand Down Expand Up @@ -5270,7 +5468,7 @@ info:
contact: {}
description: DEEIX Chat 后端 API 文档
title: DEEIX Chat API
version: "0.3.2"
version: 0.3.2
paths:
/admin/announcements:
get:
Expand Down Expand Up @@ -5636,6 +5834,32 @@ paths:
summary: 管理员保存模型按量单价
tags:
- admin-billing
/admin/billing/official-pricing/openrouter:
get:
consumes:
- application/json
description: 从 storage 缓存读取 OpenRouter 模型定价;缓存不存在、过期或 refresh=true 时由后端刷新。
parameters:
- description: 强制刷新缓存
in: query
name: refresh
type: boolean
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/internal_transport_http_billing.OpenRouterOfficialPricingResponseDoc'
"502":
description: Bad Gateway
schema:
$ref: '#/definitions/internal_transport_http_billing.ErrorDoc'
security:
- BearerAuth: []
summary: 管理员获取 OpenRouter 官方模型定价
tags:
- admin-billing
/admin/billing/plans/{id}:
patch:
consumes:
Expand Down Expand Up @@ -8385,6 +8609,72 @@ paths:
summary: 管理员查询系统事件
tags:
- admin
/admin/usage-statistics:
get:
consumes:
- application/json
description: 管理员按日期、统计对象、平台模型和计费范围查看全局费用、Token、调用次数及排名;用户与权限组筛选互斥
parameters:
- description: 开始日期(YYYY-MM-DD),默认近30天
in: query
name: start_date
type: string
- description: 结束日期(YYYY-MM-DD,包含当日)
in: query
name: end_date
type: string
- description: 用户ID
in: query
name: user_id
type: integer
- description: 权限组ID,与 user_id 互斥
in: query
name: permission_group_id
type: integer
- description: 平台模型名
in: query
name: platform_model_name
type: string
- description: 计费范围:all/free/billable
in: query
name: billing_scope
type: string
- description: 返回范围:all/models/users
in: query
name: section
type: string
- description: 模型排名指标:cost/tokens/calls
in: query
name: model_rank_by
type: string
- description: 用户排名指标:cost/tokens/calls
in: query
name: user_rank_by
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/internal_transport_http_admin.UsageStatisticsResponseDoc'
"400":
description: Bad Request
schema:
$ref: '#/definitions/internal_transport_http_admin.ErrorDoc'
"404":
description: Not Found
schema:
$ref: '#/definitions/internal_transport_http_admin.ErrorDoc'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/internal_transport_http_admin.ErrorDoc'
security:
- BearerAuth: []
summary: 管理员查询全局用量统计
tags:
- admin
/admin/user-auth-events:
get:
consumes:
Expand Down Expand Up @@ -10483,6 +10773,25 @@ paths:
summary: 查询新会话默认模型候选
tags:
- chat
/conversations/export:
get:
description: 流式导出当前用户全部会话及消息为 NDJSON 文件
produces:
- application/x-ndjson
responses:
"200":
description: NDJSON stream
schema:
type: string
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/internal_transport_http_conversation.ErrorDoc'
security:
- BearerAuth: []
summary: 导出当前用户全部对话
tags:
- chat
/conversations/project:
post:
consumes:
Expand Down
1 change: 1 addition & 0 deletions backend/internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func NewApp() (*App, error) {
adminService.SetAuthSecurityService(authService)
adminService.SetSystemEventService(systemEventService)
adminService.SetUsageLogService(billingService)
adminService.SetUsageStatisticsService(billingService)
adminService.SetOrderLogService(billingService)
adminService.SetConversationEventService(conversationService)
adminService.SetLogCleanupService(logCleanupService)
Expand Down
10 changes: 10 additions & 0 deletions backend/internal/application/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ type usageLogService interface {
ListUsageLogs(ctx context.Context, page int, pageSize int, filter billing.UsageLogListFilter) ([]domainbilling.UsageLedger, int64, error)
}

type usageStatisticsService interface {
GetUsageStatistics(ctx context.Context, filter billing.UsageStatisticsFilter) (domainbilling.UsageStatistics, error)
}

type orderLogService interface {
ListPaymentOrders(ctx context.Context, page int, pageSize int, filter billing.PaymentOrderListFilter) ([]domainbilling.PaymentOrder, int64, error)
}
Expand All @@ -119,6 +123,7 @@ type Service struct {
auditService auditService
systemEventService systemEventService
usageLogService usageLogService
usageStatisticsService usageStatisticsService
orderLogService orderLogService
conversationEventSvc conversationEventService
logCleanupService logCleanupService
Expand Down Expand Up @@ -187,6 +192,11 @@ func (s *Service) SetUsageLogService(service usageLogService) {
s.usageLogService = service
}

// SetUsageStatisticsService 注入管理员用量统计能力。
func (s *Service) SetUsageStatisticsService(service usageStatisticsService) {
s.usageStatisticsService = service
}

// SetOrderLogService 注入支付订单日志查询能力。
func (s *Service) SetOrderLogService(service orderLogService) {
s.orderLogService = service
Expand Down
Loading
Loading