- 新建 ModelPlazaService(持计费服务与定价解析器)承接广场聚合, token 模型的单价与档位全部取自 ResolveContextPricingSchedule, 渠道选择与计费同源;图片/按次模型沿用原档位合成 - 官方参考价改走计费目录(LiteLLM → 内置兜底 → 模型策略),带官方阶梯 - DTO 增加 long_context_pricing_enabled / long_context_basis / official_pricing.intervals - 前端实付与官方三列按档分行(标签只在首列,其余列按行对齐), 缓存列按档展示写/读价,边际计价以徽章与 tooltip 标注, 分组关闭阶梯时在头部说明
80 lines
2.9 KiB
TypeScript
80 lines
2.9 KiB
TypeScript
/**
|
|
* Model Plaza API(公开端点,可匿名访问)
|
|
* 以分组为中心的模型价目:分组信息 + 模型渠道定价 + LiteLLM 官方参考价。
|
|
* 带 token 请求时后端会额外返回专属分组与用户专属倍率。
|
|
*/
|
|
|
|
import { apiClient } from './client'
|
|
import type { UserPricingInterval, UserSupportedModelPricing } from './channels'
|
|
|
|
/** 官方参考价(USD per token,与计费目录同源;字段缺失 = 目录未覆盖)。 */
|
|
export interface PlazaOfficialPricing {
|
|
input_price: number | null
|
|
output_price: number | null
|
|
/** 5m 缓存写入(= LiteLLM cache_creation)。 */
|
|
cache_write_price: number | null
|
|
/** 1h 缓存写入(LiteLLM cache_creation_above_1hr),多数模型缺失。 */
|
|
cache_write_1h_price?: number | null
|
|
cache_read_price: number | null
|
|
/** 官方长上下文阶梯(多档模型才有),不受分组开关影响。 */
|
|
intervals?: UserPricingInterval[]
|
|
}
|
|
|
|
/**
|
|
* 多档时的计价基准:
|
|
* - whole_request:整单按所在档单价计价(目录阶梯、渠道区间);
|
|
* - marginal:仅超出阈值的部分按该档单价计价(平台旧规则)。
|
|
*/
|
|
export type PlazaLongContextBasis = 'whole_request' | 'marginal'
|
|
|
|
export interface PlazaModel {
|
|
name: string
|
|
platform: string
|
|
/** 实收口径的展示定价:多档时 intervals 为各档绝对单价(已由计费服务折算)。 */
|
|
pricing: UserSupportedModelPricing | null
|
|
official_pricing: PlazaOfficialPricing | null
|
|
/** 仅多档模型返回。 */
|
|
long_context_basis?: PlazaLongContextBasis
|
|
}
|
|
|
|
export interface ModelPlazaGroup {
|
|
id: number
|
|
name: string
|
|
description: string
|
|
platform: string
|
|
/** 'standard' | 'subscription' */
|
|
subscription_type: string
|
|
rate_multiplier: number
|
|
/** 登录且管理员为该用户配了专属倍率时返回;生效倍率 = user_rate ?? rate_multiplier。 */
|
|
user_rate_multiplier?: number
|
|
peak_rate_enabled: boolean
|
|
peak_start: string
|
|
peak_end: string
|
|
peak_rate_multiplier: number
|
|
is_exclusive: boolean
|
|
/** 生图独立倍率:true 时图片计费模型的实付倍率取 image_rate_multiplier,不取分组/专属倍率。 */
|
|
image_rate_independent: boolean
|
|
image_rate_multiplier: number
|
|
/** 分组是否启用长上下文阶梯计费;false 时实付列只展示最低档,官方阶梯仅供参考。 */
|
|
long_context_pricing_enabled: boolean
|
|
models: PlazaModel[]
|
|
}
|
|
|
|
export interface ModelPlazaResponse {
|
|
/** 管理员配置的全局价格说明(Markdown)。 */
|
|
description: string
|
|
groups: ModelPlazaGroup[]
|
|
}
|
|
|
|
/** 获取模型广场数据。开关未启用时后端返回 404。 */
|
|
export async function getModelPlaza(options?: { signal?: AbortSignal }): Promise<ModelPlazaResponse> {
|
|
const { data } = await apiClient.get<ModelPlazaResponse>('/model-plaza', {
|
|
signal: options?.signal
|
|
})
|
|
return data
|
|
}
|
|
|
|
export const modelPlazaAPI = { getModelPlaza }
|
|
|
|
export default modelPlazaAPI
|