Files
codex-proxy-rs/frontend/src/api/modules/key-usage.ts
T
39b35d46a0 feat(frontend): add reactive localization and refine admin layouts (#501)
* feat(frontend): add English and Traditional Chinese locales

* fix(frontend): capitalize the English login key label

* fix(frontend): capitalize standalone English labels

* feat(frontend): add reactive localization and refine admin layouts

Replace DOM text translation with domain-based Vue I18n resources for English, Simplified Chinese, and Traditional Chinese. Localize shared controls, notifications, charts, and key usage while refining table alignment, menus, and compact labels.

Expose semantic usage-window and trend-metric identifiers from the API. Pin the UI and workbench dependencies to published feature commits and preserve the original font defaults.

Co-authored-by: Codex <noreply@openai.com>

---------

Co-authored-by: Jimbb <14995924+jimbb@users.noreply.github.com>
Co-authored-by: Zyy <zyycn@users.noreply.github.com>
Co-authored-by: Codex <noreply@openai.com>
2026-10-23 11:40:38 +08:00

123 lines
3.0 KiB
TypeScript

import type { RequestOptions } from '../request'
import type { AnalyticsMetadata } from './analytics'
import type { DashboardHealthTimeline } from './dashboard'
import type { UsageBilling, UsageLatencyDetails, UsageTokenDetails } from './usage'
import request from '../request'
export interface KeyUsageConfig {
name: string
plaintextKey: string
}
export interface KeyUsageMetrics {
requests: number
inputTokens: number
outputTokens: number
cachedInputTokens: number
cacheWriteInputTokens: number
reasoningOutputTokens: number
totalTokens: number
costUsd: string | null
costIncomplete: boolean
}
export interface KeyUsageBudget {
name: string
prefix: string
maxConcurrency: number
requestsPerMinute: number
dailyLimitUsd: string
dailyUsedUsd: string
dailyResetsAt: string | null
dailyResetsAtDisplay: string | null
weeklyLimitUsd: string
weeklyUsedUsd: string
weeklyResetsAt: string | null
weeklyResetsAtDisplay: string | null
}
export interface KeyUsageTrendPoint extends KeyUsageMetrics {
time: string
bucketSeconds: number
label: string
}
export interface KeyUsageOverview {
analytics: AnalyticsMetadata
asOf: string
asOfDisplay: string
startTime: string
endTime: string
key: KeyUsageBudget
summary: KeyUsageMetrics
trend: KeyUsageTrendPoint[]
healthTimeline: DashboardHealthTimeline
}
export type KeyUsageRecordKind = 'success' | 'error' | 'all'
export interface KeyUsageRecord {
id: string
createdAt: string
createdAtDisplay: string
model: string | null
route: string | null
reasoningEffort: string | null
clientTransport: string | null
upstreamTransport: string | null
tokenDetails: UsageTokenDetails | null
billing: UsageBilling | null
latencyMs: number | null
firstTokenLatencyMs: number | null
latencyDetails: Pick<UsageLatencyDetails, 'firstEventMs' | 'firstReasoningMs' | 'firstTextMs'>
clientIp: string | null
userAgent: string | null
status: 'success' | 'error' | 'incomplete' | 'cancelled' | 'running' | 'unknown'
statusCode: number | null
}
export interface KeyUsagePage {
items: KeyUsageRecord[]
currentPage: number
pageSize: number
total: number
}
export interface KeyUsageQuery {
period: 'today' | '7d' | '30d'
asOf: number
model?: string
}
interface KeyUsageRecordsQuery extends KeyUsageQuery {
kind: KeyUsageRecordKind
currentPage: number
pageSize: number
}
export function getKeyUsageOverview(data: KeyUsageQuery, options: RequestOptions = {}) {
return request<KeyUsageOverview>({
url: '/api/key-usage/overview',
method: 'GET',
params: data,
...options,
})
}
export function getKeyUsageConfig(options: RequestOptions = {}) {
return request<KeyUsageConfig>({
url: '/api/key-usage/config',
method: 'GET',
...options,
})
}
export function getKeyUsageRecords(data: KeyUsageRecordsQuery, options: RequestOptions = {}) {
return request<KeyUsagePage>({
url: '/api/key-usage/records',
method: 'GET',
params: data,
...options,
})
}