{"record":{"id":"d0a33624656f3dc5","repo":"BigPizzaV3/CodexPlusPlus","slug":"sub2api-key-billing","errorCode":null,"errorMessage":"倍率接口返回结构不是 sub2api.key_billing","messagePattern":"倍率接口返回结构不是 sub2api\\.key_billing","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/sub2api.rs","lineNumber":108,"sourceCode":"    let cleaned = base_url.trim().trim_end_matches('/');\n    if cleaned.is_empty() {\n        return String::new();\n    }\n    if cleaned.ends_with(\"/sub2api/billing\") {\n        return cleaned.to_string();\n    }\n    if crate::protocol_proxy::has_version_suffix(cleaned) {\n        return format!(\"{cleaned}/sub2api/billing\");\n    }\n    format!(\"{cleaned}/v1/sub2api/billing\")\n}\n\nfn validate_sub2api_billing_response(response: &Sub2ApiBillingResponse) -> anyhow::Result<()> {\n    if response.object != \"sub2api.key_billing\"\n        || response.schema_version != 1\n        || response.billing_scope != \"token\"\n    {\n        anyhow::bail!(\"倍率接口返回结构不是 sub2api.key_billing\");\n    }\n    for value in [\n        response.group_rate_multiplier,\n        response.resolved_rate_multiplier,\n        response.effective_rate_multiplier,\n    ] {\n        if !value.is_finite() || value < 0.0 {\n            anyhow::bail!(\"倍率接口返回了无效倍率\");\n        }\n    }\n    if let Some(value) = response.user_rate_multiplier {\n        if !value.is_finite() || value < 0.0 {\n            anyhow::bail!(\"倍率接口返回了无效用户倍率\");\n        }\n    }\n    if response.observed_at.trim().is_empty() {\n        anyhow::bail!(\"倍率接口缺少观测时间\");\n    }","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/sub2api.rs#L90-L126","documentation":"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.","triggerScenarios":"fetch_sub2api_billing_info 反序列化成功但响应的 object/schema_version/billing_scope 任一字段与预期常量不符。","commonSituations":"Base URL 指向了非 sub2api 的兼容网关；上游升级了 schema_version（>1）；端点返回的是其他 object 类型（如 key_info）的 JSON。","solutions":["确认 Base URL 指向真正的 sub2api 服务而非其他网关","升级本库以支持上游新 schema_version","打印完整响应体确认实际返回的 object 类型"],"exampleFix":"// before\nif response.object != \"sub2api.key_billing\"\n    || response.schema_version != 1\n    || response.billing_scope != \"token\"\n{\n    anyhow::bail!(\"倍率接口返回结构不是 sub2api.key_billing\");\n}\n// after\nif response.object != \"sub2api.key_billing\" {\n    anyhow::bail!(\"倍率接口返回结构不是 sub2api.key_billing（实际 object: {}，schema_version: {}）\",\n        response.object, response.schema_version);\n}\nif response.schema_version != 1 {\n    anyhow::bail!(\"不支持的 schema_version: {}\", response.schema_version);\n}","handlingStrategy":"try-catch","validationCode":"// 请求后先打印原始响应关键字段再交给库校验\nlet raw: serde_json::Value = serde_json::from_str(&body)?;\nprintln!(\"object={:?} schema_version={:?}\", raw[\"object\"], raw[\"schema_version\"]);","typeGuard":null,"tryCatchPattern":"match fetch_sub2api_billing_info(&profile).await {\n    Err(e) if e.to_string().contains(\"返回结构不是\") => {\n        eprintln!(\"上游不是 sub2api 或版本不兼容：{e}，请核对 Base URL\");\n    }\n    other => other?,\n}","preventionTips":["确认 Base URL 指向 sub2api 服务而非其他兼容网关","上游升级 schema 后同步升级本库","对接前用 curl 验证响应的 object 字段"],"tags":["schema","validation","sub2api","api-contract"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}