diff --git a/src/agents/live-auth-keys.ts b/src/agents/live-auth-keys.ts index 8266d4a1b52..50ddd64bcf3 100644 --- a/src/agents/live-auth-keys.ts +++ b/src/agents/live-auth-keys.ts @@ -90,7 +90,11 @@ export function isAnthropicBillingError(message: string): boolean { if (lower.includes("billing") && lower.includes("disabled")) { return true; } - if (lower.includes("402")) { + if ( + /(?:status|code|http|error)\s*[:=]?\s*402\b|(?:got|returned|received|a)\s+(?:a\s+)?402\b|^\s*402\s+payment/i.test( + lower, + ) + ) { return true; } return false; diff --git a/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts b/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts index 00c6d4910f8..5529be9c4a2 100644 --- a/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts +++ b/src/agents/pi-embedded-helpers.isbillingerrormessage.test.ts @@ -35,6 +35,9 @@ describe("isBillingErrorMessage", () => { "Room 402 is available", "Error code 403 was returned, not 402-related", "The building at 402 Main Street", + "processed 402 records", + "402 items found in the database", + "port 402 is open", ]; for (const sample of falsePositives) { expect(isBillingErrorMessage(sample)).toBe(false); @@ -47,6 +50,9 @@ describe("isBillingErrorMessage", () => { "error code 402", "http 402", "status=402 payment required", + "got a 402 from the API", + "returned 402", + "received a 402 response", ]; for (const sample of realErrors) { expect(isBillingErrorMessage(sample)).toBe(true); diff --git a/src/agents/pi-embedded-helpers/errors.ts b/src/agents/pi-embedded-helpers/errors.ts index 3ca9261bf49..99d230ed307 100644 --- a/src/agents/pi-embedded-helpers/errors.ts +++ b/src/agents/pi-embedded-helpers/errors.ts @@ -535,7 +535,7 @@ const ERROR_PATTERNS = { overloaded: [/overloaded_error|"type"\s*:\s*"overloaded_error"/i, "overloaded"], timeout: ["timeout", "timed out", "deadline exceeded", "context deadline exceeded"], billing: [ - /(?:status|code|http|error)\s*[:=]?\s*402\b|^\s*402\s+payment/i, + /(?:status|code|http|error)\s*[:=]?\s*402\b|(?:got|returned|received|a)\s+(?:a\s+)?402\b|^\s*402\s+payment/i, "payment required", "insufficient credits", "credit balance",