- 使用 SQLite 保存关联后的请求生命周期和用量记录 - 支持长上下文阶梯价格和可配置的 Fast 计费倍率 - 添加管理接口和可配置列的用量面板 - 保留失败、取消、重试和 compact 请求,便于计费核对
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
// Package collection 定义 CPA 用量观察及其采集服务。
|
|
package collection
|
|
|
|
import "time"
|
|
|
|
// Record 是当前请求明细功能保存的用量观察。
|
|
// 它不包含汇总结果,暂时拿不到的字段使用零值或 NULL。
|
|
type Record struct {
|
|
RequestID string
|
|
ExecutionID string
|
|
TraceID string
|
|
RequestedAt time.Time
|
|
APIKey string
|
|
KeyAlias string
|
|
Model string
|
|
ReasoningEffort string
|
|
ServiceTier string
|
|
Speed string
|
|
Failed bool
|
|
ExecutorType string
|
|
RequestType string
|
|
Endpoint string
|
|
InputTokens int64
|
|
OutputTokens int64
|
|
TotalTokens int64
|
|
CachedTokens int64
|
|
CacheReadTokens int64
|
|
CacheWriteTokens int64
|
|
ReasoningTokens int64
|
|
TTFT time.Duration
|
|
Latency time.Duration
|
|
CostMicros *int64
|
|
PriceTier string
|
|
FastRequested bool
|
|
FastPricingApplied bool
|
|
PriceMultiplierNumerator int64
|
|
PriceMultiplierDenominator int64
|
|
ClientIP string
|
|
Outcome string
|
|
StatusCode int
|
|
Error string
|
|
}
|
|
|
|
// RequestRecord 保存一次模型执行的终态,即使没有产生 Usage 也必须存在。
|
|
type RequestRecord struct {
|
|
RequestID string
|
|
TraceID string
|
|
RequestedAt time.Time
|
|
CompletedAt time.Time
|
|
Model string
|
|
RequestedModel string
|
|
SourceFormat string
|
|
Stream bool
|
|
Outcome string
|
|
StatusCode int
|
|
Error string
|
|
Endpoint string
|
|
}
|