diff --git a/packages/ai/src/provider-error.ts b/packages/ai/src/provider-error.ts index e1f24c23f19..1822eede06c 100644 --- a/packages/ai/src/provider-error.ts +++ b/packages/ai/src/provider-error.ts @@ -176,8 +176,9 @@ const AUTH_TEXT = /incorrect api key provided/i const RATE_LIMIT_TEXT = /rate increased too quickly|rate[-_\s]?limit|too[_\s]?many[_\s]?requests/i // Only consulted on 429, where throttles and account caps share a status. // Z.ai reports balance, plan expiry, plan limits, and plan model access on 429. +// Cerebras reports its per-minute token throttle as `token_quota_exceeded`; that is a rate limit. const QUOTA_TEXT = - /insufficient[-_\s]?(?:quota|balance)|quota[-_\s]?exceeded|budget exceeded|usage limit|limit exhausted|package has expired|plan does not yet include/i + /insufficient[-_\s]?(?:quota|balance)|(? { expect(isContextOverflow("Too many tokens")).toBe(true) }) + test("classifies 429 token throttles as retryable rate limits, not context overflow", () => { + const bodies = [ + // Cerebras, captured live + '{"message":"Tokens per minute limit exceeded - too many tokens processed.","type":"too_many_tokens_error","param":"quota","code":"token_quota_exceeded"}', + '{"message":"Token limit reached: too many tokens per minute for this model."}', + ] + for (const body of bodies) { + const error = new AIError({ + reason: classifyProviderFailure({ message: providerErrorMessage(body), status: 429, rawBody: body }), + }) + expect(error.reason._tag).toBe("RateLimit") + expect(isRetryable(error)).toBe(true) + } + }) + test("does not infer context overflow from known throttling exceptions", () => { const cases = [ { status: 429, data: { code: "ThrottlingException" } },