BigPizzaV3/CodexPlusPlus · error
倍率接口返回结构不是 sub2api.key_billing
Error message
倍率接口返回结构不是 sub2api.key_billing
What it means
validate_sub2api_billing_response is a schema guard: it requires object == 'sub2api.key_billing', schema_version == 1, and billing_scope == 'token'. This bail means the endpoint answered 200 but the JSON is not the expected billing object — wrong endpoint version or a non-sub2api service.
Solutions
- 确认 Base URL 指向真正的 sub2api 服务而非其他网关
- 升级本库以支持上游新 schema_version
- 打印完整响应体确认实际返回的 object 类型
Example fix
// before
if response.object != "sub2api.key_billing"
|| response.schema_version != 1
|| response.billing_scope != "token"
{
anyhow::bail!("倍率接口返回结构不是 sub2api.key_billing");
}
// after
if response.object != "sub2api.key_billing" {
anyhow::bail!("倍率接口返回结构不是 sub2api.key_billing(实际 object: {},schema_version: {})",
response.object, response.schema_version);
}
if response.schema_version != 1 {
anyhow::bail!("不支持的 schema_version: {}", response.schema_version);
} Defensive patterns
Strategy: try-catch
Validate before calling
// 请求后先打印原始响应关键字段再交给库校验
let raw: serde_json::Value = serde_json::from_str(&body)?;
println!("object={:?} schema_version={:?}", raw["object"], raw["schema_version"]); Try / catch
match fetch_sub2api_billing_info(&profile).await {
Err(e) if e.to_string().contains("返回结构不是") => {
eprintln!("上游不是 sub2api 或版本不兼容:{e},请核对 Base URL");
}
other => other?,
} Prevention
- 确认 Base URL 指向 sub2api 服务而非其他兼容网关
- 上游升级 schema 后同步升级本库
- 对接前用 curl 验证响应的 object 字段
When it happens
Trigger: fetch_sub2api_billing_info 反序列化成功但响应的 object/schema_version/billing_scope 任一字段与预期常量不符。
Common situations: Base URL 指向了非 sub2api 的兼容网关;上游升级了 schema_version(>1);端点返回的是其他 object 类型(如 key_info)的 JSON。
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/d0a33624656f3dc5.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/sub2api.rs:108
let cleaned = base_url.trim().trim_end_matches('/');
if cleaned.is_empty() {
return String::new();
}
if cleaned.ends_with("/sub2api/billing") {
return cleaned.to_string();
}
if crate::protocol_proxy::has_version_suffix(cleaned) {
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!("倍率接口缺少观测时间");
}View on GitHub (pinned to b1ed92e5e4)