You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Warning: issues with this template removed, section headings deleted, or content cleared may be closed directly. Repeated abusive submissions may result in a block.
Your current newapi version
请填写当前版本号,例如:v1.0.0
Submission Checks
I have confirmed there are no similar issues
I have thoroughly read the docs at https://docs.newapi.ai/ and the project README, and confirmed the current version cannot meet my needs
I have not removed any guidance or section headings from this template and will complete it as requested
I understand that maintainers have limited time and issues that do not follow this template may be ignored or closed directly
根据我对项目代码的深入分析,现在来回答你的问题并整理需求。
分析结论
当前项目不支持这个功能,但可以实现。
当前计费架构
graph TD A[用户请求] --> B{获取模型计费模式} B -->|billing_mode = ratio| C[按量计费<br/>token数 × 模型倍率 × 分组倍率] B -->|billing_mode = tiered_expr| D[表达式计费<br/>自定义公式] B -->|modelPrice 存在| E[按次计费<br/>固定价格 × 分组倍率] F[分组系统] --> G[GroupRatio: 仅作为价格乘数] style B fill:#ff6b6b,color:#fff style F fill:#ffa94d,color:#fff核心限制
计费模式(
billing_mode)是按模型全局配置的,不是按 (模型, 分组) 维度配置:GetBillingMode(model)— 只接受模型名,不接受分组参数GetModelPrice(name, false)— 全局 modelPriceMap,无分组维度ModelPriceHelper()— 计费模式判断与分组无关分组(Group)目前只影响价格乘数(
GroupRatio),不影响计费模式本身。以下是按你要求整理的需求文档:
Read This First (Do Not Remove This Section)
Your current newapi version
请填写当前版本号,例如:
v1.0.0Submission Checks
Feature Description
需求:支持同一模型按分组配置不同计费模式(按次/按量)
背景: 当前系统的计费模式(
ratio按量 /model_price按次 /tiered_expr表达式)是按模型全局配置的,所有分组共享同一种计费方式。分组(Group)仅作为价格乘数(GroupRatio)影响最终费用,无法改变计费模式本身。期望能力: 同一个模型,在不同分组下可以使用不同的计费模式。例如:
gpt-4omodel_price)gpt-4oratio)Use Case
场景描述:
运营方通过 A、B 两个渠道接入了同一个上游模型(如
gpt-4o),希望对不同用户群体采用差异化计费策略:当前无法实现的原因:
billing_setting.BillingMode的数据结构是map[string]string(模型名→计费模式),没有分组维度ratio_setting.modelPriceMap(按次价格)是全局的,不区分分组relay/helper/price.go中的ModelPriceHelper计费模式判断逻辑不考虑分组信息model/pricing.go中的定价接口 返回的Pricing结构中,QuotaType、ModelPrice、ModelRatio均为模型级别,无分组维度实现方向建议:
需要将计费模式从「按模型」维度扩展为「按模型+分组」维度,涉及以下模块改造:
BillingMode/modelPriceMap增加分组维度(如map[string]map[string]string)ModelPriceHelper在判断计费模式时传入当前分组信息/api/pricing返回分组级别的计费模式和价格