treats 403 from anthropic as key dead

This commit is contained in:
nai-degen
2023-12-11 09:13:53 -06:00
parent e0624e30fd
commit 0d3682197c
2 changed files with 8 additions and 3 deletions
+5 -1
View File
@@ -314,7 +314,11 @@ const handleUpstreamErrors: ProxyResHandlerWithBody = async (
keyPool.disable(req.key!, "revoked");
errorPayload.proxy_note = `API key is invalid or revoked. ${tryAgainMessage}`;
} else if (statusCode === 403) {
// Amazon is the only service that returns 403.
if (service === "anthropic") {
keyPool.disable(req.key!, "revoked");
errorPayload.proxy_note = `API key is invalid or revoked. ${tryAgainMessage}`;
return;
}
switch (errorType) {
case "UnrecognizedClientException":
// Key is invalid.
@@ -48,13 +48,14 @@ export class AnthropicKeyChecker extends KeyCheckerBase<AnthropicKey> {
protected handleAxiosError(key: AnthropicKey, error: AxiosError) {
if (error.response && AnthropicKeyChecker.errorIsAnthropicAPIError(error)) {
const { status, data } = error.response;
if (status === 401) {
if (status === 401 || status === 403) {
this.log.warn(
{ key: key.hash, error: data },
"Key is invalid or revoked. Disabling key."
);
this.updateKey(key.hash, { isDisabled: true, isRevoked: true });
} else if (status === 429) {
}
else if (status === 429) {
switch (data.error.type) {
case "rate_limit_error":
this.log.warn(