From d7a4829d1337bf6508d00a0e202c60e050481f49 Mon Sep 17 00:00:00 2001 From: nai-degen Date: Wed, 19 Jul 2023 10:28:38 -0500 Subject: [PATCH] handles keys which have been banned (but not revoked) by openai --- src/key-management/openai/checker.ts | 7 +++++++ src/proxy/middleware/response/index.ts | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/src/key-management/openai/checker.ts b/src/key-management/openai/checker.ts index 5e16223..be29862 100644 --- a/src/key-management/openai/checker.ts +++ b/src/key-management/openai/checker.ts @@ -221,6 +221,13 @@ export class OpenAIKeyChecker { "Key is out of quota. Disabling key." ); this.updateKey(key.hash, { isDisabled: true }); + } + else if (status === 429 && data.error.type === "access_terminated") { + this.log.warn( + { key: key.hash, isTrial: key.isTrial, error: data }, + "Key has been terminated due to policy violations. Disabling key." + ); + this.updateKey(key.hash, { isDisabled: true }); } else { this.log.error( { key: key.hash, status, error: data }, diff --git a/src/proxy/middleware/response/index.ts b/src/proxy/middleware/response/index.ts index 3580eb7..4f02a3c 100644 --- a/src/proxy/middleware/response/index.ts +++ b/src/proxy/middleware/response/index.ts @@ -377,6 +377,10 @@ function handleOpenAIRateLimitError( // Billing quota exceeded (key is dead, disable it) keyPool.disable(req.key!); errorPayload.proxy_note = `Assigned key's quota has been exceeded. ${tryAgainMessage}`; + } else if (type === "access_terminated") { + // Account banned (key is dead, disable it) + keyPool.disable(req.key!); + errorPayload.proxy_note = `Assigned key has been banned by OpenAI for policy violations. ${tryAgainMessage}`; } else if (type === "billing_not_active") { // Billing is not active (key is dead, disable it) keyPool.disable(req.key!);