fix: classify budget errors in error envelopes

This commit is contained in:
wlx committed 2026-09-28 08:49:03 +08:00
1 parent e0c926104e
commit 88c55cc6a9
2 files changed
+11

No files matched your search

@@ -215,6 +215,9 @@ public class OpenAiCompatibleProvider {
*/
static ApiException classifyUpstreamError(int status, String body) {
String details = body == null ? "" : body.toLowerCase(java.util.Locale.ROOT);
if (requiresLargerOutputBudget(details)) {
return new ApiException("INVALID_MAX_TOKENS", "上游模型要求 max_tokens 大于 1024,请提高输出 Token 上限后重试", 400);
}
if (status == 408 || status == 504 || details.matches(".*(request|gateway|upstream).{0,12}(timed out|timeout|超时).*")) {
return new ApiException("UPSTREAM_PROVIDER_TIMEOUT", "上游模型供应商响应超时", 504);
}
@@ -94,4 +94,12 @@ class ProviderErrorClassificationTest {
assertTrue(OpenAiCompatibleProvider.requiresLargerOutputBudget(
"max_tokens must be greater than 1024 for manual Claude thinking"));
}
@Test
void classifiesMinimumBudgetErrorsEvenWhenRelayUsesHttp200Envelope() {
var error = OpenAiCompatibleProvider.classifyUpstreamError(200,
"{\"error\":{\"message\":\"max_tokens must be greater than 1024\"}}");
assertEquals("INVALID_MAX_TOKENS", error.getCode());
assertEquals(400, error.getStatus());
}
}