fix(agents): fail over on billing/credits errors

This commit is contained in:
Peter Steinberger
2026-01-09 21:17:00 +01:00
parent e0089bb4eb
commit 65cb9dc3f7
6 changed files with 85 additions and 4 deletions

View File

@@ -9,6 +9,7 @@ import {
} from "./model-selection.js";
import {
isAuthErrorMessage,
isBillingErrorMessage,
isRateLimitErrorMessage,
} from "./pi-embedded-helpers.js";
@@ -82,7 +83,7 @@ function isTimeoutErrorMessage(raw: string): boolean {
function shouldFallbackForError(err: unknown): boolean {
const statusCode = getStatusCode(err);
if (statusCode && [401, 403, 429].includes(statusCode)) return true;
if (statusCode && [401, 402, 403, 429].includes(statusCode)) return true;
const code = getErrorCode(err).toUpperCase();
if (
["ETIMEDOUT", "ESOCKETTIMEDOUT", "ECONNRESET", "ECONNABORTED"].includes(
@@ -96,6 +97,7 @@ function shouldFallbackForError(err: unknown): boolean {
return (
isAuthErrorMessage(message) ||
isRateLimitErrorMessage(message) ||
isBillingErrorMessage(message) ||
isTimeoutErrorMessage(message)
);
}