handles 'this organization is disabled' error from anthropic

This commit is contained in:
nai-degen 2024-03-06 00:42:10 -06:00
parent ddf34685df
commit 8f46bd4397
2 changed files with 22 additions and 0 deletions

View File

@ -450,6 +450,17 @@ async function handleAnthropicBadRequestError(
return;
}
const isDisabled = error?.message?.match(/organization has been disabled/i);
if (isDisabled) {
req.log.warn(
{ key: req.key?.hash, message: error?.message },
"Anthropic key has been disabled."
);
keyPool.disable(req.key!, "revoked");
errorPayload.proxy_note = `Assigned key has been disabled. ${error?.message}`;
return;
}
errorPayload.proxy_note = `Unrecognized error from the API. (${error?.message})`;
}

View File

@ -61,15 +61,26 @@ export class AnthropicKeyChecker extends KeyCheckerBase<AnthropicKey> {
protected handleAxiosError(key: AnthropicKey, error: AxiosError) {
if (error.response && AnthropicKeyChecker.errorIsAnthropicAPIError(error)) {
const { status, data } = error.response;
// They send billing/revocation errors as 400s for some reason.
// The type is always invalid_request_error, so we have to check the text.
const isOverQuota =
data.error?.message?.match(/usage blocked until/i) ||
data.error?.message?.match(/credit balance is too low/i);
const isDisabled = data.error?.message?.match(
/organization has been disabled/i
);
if (status === 400 && isOverQuota) {
this.log.warn(
{ key: key.hash, error: data },
"Key is over quota. Disabling key."
);
this.updateKey(key.hash, { isDisabled: true, isOverQuota: true });
} else if (status === 400 && isDisabled) {
this.log.warn(
{ key: key.hash, error: data },
"Key's organization is disabled. Disabling key."
);
this.updateKey(key.hash, { isDisabled: true, isRevoked: true });
} else if (status === 401 || status === 403) {
this.log.warn(
{ key: key.hash, error: data },