BigPizzaV3/CodexPlusPlus · error
倍率接口返回了无效倍率
Error message
倍率接口返回了无效倍率
What it means
The validator loops over group_rate_multiplier, resolved_rate_multiplier, and effective_rate_multiplier and bails if any is non-finite (NaN/inf) or negative. This protects downstream cost math from garbage multiplier values that would produce nonsense billing estimates.
Solutions
- 在 sub2api 管理后台检查并修正分组/密钥的倍率配置为非负有限值
- 直接请求倍率端点查看原始 JSON,确认是上游数据问题
- 升级上游 sub2api 版本修复序列化 bug
Defensive patterns
Strategy: try-catch
Validate before calling
fn multipliers_sane(body: &serde_json::Value) -> bool {
["group_rate_multiplier", "resolved_rate_multiplier", "effective_rate_multiplier"]
.iter()
.all(|k| body[k].as_f64().map(|v| v.is_finite() && v >= 0.0).unwrap_or(false))
} Try / catch
match fetch_sub2api_billing_info(&profile).await {
Err(e) if e.to_string().contains("无效倍率") => {
eprintln!("上游倍率数据异常:{e},请到 sub2api 后台检查倍率配置");
}
other => other?,
} Prevention
- 在 sub2api 后台定期核对分组/密钥倍率为非负有限值
- 上游异常时先用 curl 查看原始 JSON 排除传输层问题
- 升级 sub2api 修复倍率字段的序列化 bug
When it happens
Trigger: 上游返回的任一必填倍率为 NaN、正负无穷或负数(JSON 解析为 f64 后 is_finite() 为假或 < 0.0)。
Common situations: 上游数据库倍率字段损坏或未初始化;上游 bug 序列化了 null/Infinity;配置了负数折扣倍率的上游。
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/1b60e874cb05030c.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/sub2api.rs:116
return format!("{cleaned}/sub2api/billing");
}
format!("{cleaned}/v1/sub2api/billing")
}
fn validate_sub2api_billing_response(response: &Sub2ApiBillingResponse) -> anyhow::Result<()> {
if response.object != "sub2api.key_billing"
|| response.schema_version != 1
|| response.billing_scope != "token"
{
anyhow::bail!("倍率接口返回结构不是 sub2api.key_billing");
}
for value in [
response.group_rate_multiplier,
response.resolved_rate_multiplier,
response.effective_rate_multiplier,
] {
if !value.is_finite() || value < 0.0 {
anyhow::bail!("倍率接口返回了无效倍率");
}
}
if let Some(value) = response.user_rate_multiplier {
if !value.is_finite() || value < 0.0 {
anyhow::bail!("倍率接口返回了无效用户倍率");
}
}
if response.observed_at.trim().is_empty() {
anyhow::bail!("倍率接口缺少观测时间");
}
Ok(())
}
fn sub2api_error_message(body: &str) -> Option<String> {
let payload: Value = serde_json::from_str(body).ok()?;
for path in [&["error", "message"][..], &["message"][..], &["error"][..]] {
let mut current = &payload;
for key in path {View on GitHub (pinned to b1ed92e5e4)