{"type":"root","children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"这篇解决什么问题"}]},{"type":"text","value":"：让你不用真的把额度花光、也不用等一次真实故障，就能演练各种失败场景。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Mock（演习）不会真的打上游。它让 Tare 按指定剧本，返回和真实失败"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"形状一致"}]},{"type":"text","value":"的错误。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"为什么需要它"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"演习最难自己造的就是错误分支。真要撞到额度用尽，得先把钱花光；真要遇上一次上游故障，只能等它自己发生，不由你挑时候。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"给某一把 key 挂上一种固定场景，用这把 key 打的请求就会直接返回模拟结果，不会真的打到上游。不花一个 token，也不用等一次真实故障出现。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"什么时候用 Mock"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"上线前验证客户端如何处理限流、欠费、额度用尽。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"验证客服或前端展示给终端用户的错误文案。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"验证重试逻辑是否只对该重试的错误重试。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"验证监控和告警能否识别失败。"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"推荐演练顺序"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"先用正常 Mock 响应（"},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"SUCCESS"}]},{"type":"text","value":"）确认调用链路可控。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"演练 429，确认客户端读取了 "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"Retry-After"}]},{"type":"text","value":"。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"演练额度用尽和欠费，确认不会盲目重试。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"演练上游全挂，确认前端和告警都能识别。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"演练 DLP 拦截，确认不会把敏感内容继续发给上游。"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"详细说明"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h4","properties":{},"children":[{"type":"text","value":"挂上一个场景"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"控制台路径："},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"API Keys"}]},{"type":"text","value":" → 点这把 key → "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Testing"}]},{"type":"text","value":" → "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Mock responses"}]},{"type":"text","value":"。场景生效期间，列表里这把 key 显示 "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Mocked"}]},{"type":"text","value":"。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"也可以直接调接口："}]},{"type":"text","value":"\n"},{"type":"element","tagName":"pre","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"text","value":"curl -X PUT https://tare.jamerly.ai/v1/mocks/{apiKeyId} \\\n  -H \"Authorization: Bearer $TARE_KEY\" -H \"Content-Type: application/json\" \\\n  -d '{\"scenario\":\"UPSTREAM_TIMEOUT\",\"enabled\":true}'\n"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"blockquote","properties":{"data-alert":"warning"},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"只圈定你指名的这把 key，不是整个账号。"}]},{"type":"text","value":" 用管理凭据操作时，也只能动它名下的 key。拿一把专门的 key 去演习，不会因此把同事的生产流量变成假数据。"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h4","properties":{},"children":[{"type":"text","value":"场景清单"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"GET /v1/mocks/scenarios"}]},{"type":"text","value":" 会给出完整列表，"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"从这里读，不要在客户端写死"}]},{"type":"text","value":"，因为清单以后可能增加："}]},{"type":"text","value":"\n"},{"type":"element","tagName":"table","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"thead","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"th","properties":{},"children":[{"type":"text","value":"场景"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"th","properties":{},"children":[{"type":"text","value":"模拟的是"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tbody","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"KEY_CREDIT_EXHAUSTED"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"这把 key 自己的消费上限用完"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"BUDGET_EXHAUSTED"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"账号月度预算用完"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"ACCOUNT_BALANCE_INSUFFICIENT"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"账号余额耗尽"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"RATE_LIMITED"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"请求太频繁"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"UPSTREAM_TIMEOUT"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"上游一直不响应"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"UPSTREAM_ERROR"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"上游返回 5xx"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"INVALID_KEY"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"凭据被拒"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"MODEL_NOT_FOUND"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"请求的模型不存在"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"BAD_REQUEST"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"请求格式错误"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"CONTENT_FILTERED"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"内容策略拦截"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"tr","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"SUCCESS"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"td","properties":{},"children":[{"type":"text","value":"正常响应，内容由"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"你"}]},{"type":"text","value":"指定（见下文）"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"每一种失败场景返回的错误形状，和真实发生时 Tare 会给的一模一样。目的是让你的代码走到"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"真正的那条分支"}]},{"type":"text","value":"，而不是一个近似的版本。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h4","properties":{},"children":[{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"SUCCESS"}]},{"type":"text","value":"：固定响应，不是失败"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"这是唯一一种非失败场景。把 "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"responseBody"}]},{"type":"text","value":" 设成你想要的那段完整 JSON，会原样返回；填纯文本则包装成一条普通的 completion。可选加上 "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"delayMs"}]},{"type":"text","value":" 模拟延迟。适合测试正常路径：拿到一个稳定可预测的输出，而不是真实模型那种会变化的回答。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h4","properties":{},"children":[{"type":"text","value":"过期时间"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"演习本来就该是临时的：不填 "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"expiresAt"}]},{"type":"text","value":"，默认从开启时算起 "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"4 小时"}]},{"type":"text","value":"后过期，没有「永久」这个选项。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"blockquote","properties":{"data-alert":"note"},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"一个没人记得开过的演习，挂在一把不知不觉变成生产 key 的凭据上，比重新开一次的麻烦要糟得多。"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h4","properties":{},"children":[{"type":"text","value":"不会影响的地方"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"别的 key 上的调用不受影响。"}]},{"type":"text","value":" 演习是挂在 key 上的属性，不是账号级的。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"不消耗一个 token"}]},{"type":"text","value":"，演习从不会真的打到上游。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"关闭或删除从下一次调用起生效"}]},{"type":"text","value":"；已经在处理中的调用不受影响。"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h4","properties":{},"children":[{"type":"text","value":"演习仍然会留下痕迹，也可能计费"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"演习调用"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"永远会写一条用量记录"}]},{"type":"text","value":"，标成 "},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"MOCKED"}]},{"type":"text","value":"，所以无论哪种场景，都不计入你的成功率统计（"},{"type":"element","tagName":"code","properties":{},"children":[{"type":"text","value":"SUCCESS"}]},{"type":"text","value":" 场景不会把它拉高，失败场景也不会把它拉低）。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"它走的是"},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"和真实调用同一条计费链路"}]},{"type":"text","value":"：token 用量始终是 0，但如果这个模型走的渠道配了单次调用的最低收费，这笔最低收费照收。这次调用同样要先过余额、key 额度、预算这三道闸，和真实调用一样。已经用尽额度的 key，没法靠开演习绕过检查、顺便蹭一笔路由费。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"blockquote","properties":{"data-alert":"warning"},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"开关演习本身也会留痕。"}]},{"type":"text","value":" 生产流量悄悄开始返回假数据这件事，之后一定会有人要你解释那段时间发生了什么。详见 "},{"type":"element","tagName":"a","properties":{"href":"audit-trail"},"children":[{"type":"text","value":"审计日志"}]},{"type":"text","value":"。"}]},{"type":"text","value":"\n"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"h3","properties":{},"children":[{"type":"text","value":"下一步"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"想看清各种错误码的真实含义：读 "},{"type":"element","tagName":"a","properties":{"href":"errors"},"children":[{"type":"text","value":"错误码"}]},{"type":"text","value":"。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"想了解额度、预算怎么配：读 "},{"type":"element","tagName":"a","properties":{"href":"limits"},"children":[{"type":"text","value":"限流与配额"}]},{"type":"text","value":"。"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"想知道账号上的改动都会被记在哪：读 "},{"type":"element","tagName":"a","properties":{"href":"audit-trail"},"children":[{"type":"text","value":"审计日志"}]},{"type":"text","value":"。"}]},{"type":"text","value":"\n"}]}]}