Skip to content

Commit 0b22cf9

Browse files
authored
fix(ai): treat Tencent's 400003 input limit error as context overflow (#66796)
1 parent 0081ffa commit 0b22cf9

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎packages/ai/src/provider-error.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const patterns = [
1818
/input is too long for (?:the )?(?:requested|selected) model/i,
1919
// OpenCode Go
2020
/too large for the model'?s configured input limit/i,
21+
// Tencent TokenHub code 400003, which OpenCode Go passes through for Hy models.
22+
/input tokens exceeds? the model'?s? context limit/i,
2123
// Cloudflare Workers AI reports this as HTTP 413.
2224
/exceeded this model context window limit/i,
2325
/exceeds the context window/i,

‎packages/ai/test/provider-error.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,28 @@ describe("provider error classification", () => {
2121
"Prompt exceeds max length",
2222
"The input is too long for the selected model.",
2323
"This text request is too large for the model's configured input limit.",
24+
"[400003] Input tokens exceed the model context limit.",
25+
"The number of input tokens exceeds the model's context limit.",
2426
// LiteLLM's own check, before it calls the model.
2527
"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window large enough for this call.",
2628
]
2729

2830
expect(messages.every(isContextOverflow)).toBe(true)
2931
})
3032

33+
test("classifies Tencent's 400003 passed through OpenCode Go as context overflow", () => {
34+
const go = {
35+
error: {
36+
type: "server_error",
37+
message: "Upstream request failed: [400003] Input tokens exceed the model context limit.",
38+
},
39+
}
40+
41+
expect(
42+
classifyProviderFailure({ message: go.error.message, status: 400, rawBody: JSON.stringify(go) }),
43+
).toMatchObject({ _tag: "InvalidRequest", classification: "context-overflow" })
44+
})
45+
3146
test("classifies Anthropic request_too_large as recoverable overflow", () => {
3247
expect(
3348
classifyProviderFailure({

0 commit comments

Comments
 (0)