Skip to content

Commit

Permalink
Update disabled channel
Browse files Browse the repository at this point in the history
  • Loading branch information
ye4293 committed Aug 31, 2024
1 parent f977469 commit 82f34d3
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions monitor/manage.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package monitor

import (
"github.com/songquanpeng/one-api/common/config"
"github.com/songquanpeng/one-api/relay/model"
"net/http"
"strings"

"github.com/songquanpeng/one-api/common/config"
"github.com/songquanpeng/one-api/relay/model"
)

func ShouldDisableChannel(err *model.Error, statusCode int) bool {
Expand All @@ -14,37 +15,29 @@ func ShouldDisableChannel(err *model.Error, statusCode int) bool {
if err == nil {
return false
}
if statusCode == http.StatusUnauthorized {
if statusCode == http.StatusUnauthorized || statusCode == http.StatusTooManyRequests {
return true
}
switch err.Type {
case "insufficient_quota":
return true
// https://docs.anthropic.com/claude/reference/errors
case "authentication_error":
return true
case "permission_error":
return true
case "forbidden":
case "insufficient_quota", "authentication_error", "permission_error", "forbidden":
return true
}
if err.Code == "invalid_api_key" || err.Code == "account_deactivated" {
if err.Code == "invalid_api_key" {
return true
}
if strings.HasPrefix(err.Message, "Your credit balance is too low") { // anthropic
return true
} else if strings.HasPrefix(err.Message, "This organization has been disabled.") {
return true
}
//if strings.Contains(err.Message, "quota") {
// return true
//}
if strings.Contains(err.Message, "credit") {
return true
}
if strings.Contains(err.Message, "balance") {

lowerMessage := strings.ToLower(err.Message)
if strings.Contains(lowerMessage, "your access was terminated") ||
strings.Contains(lowerMessage, "violation of our policies") ||
strings.Contains(lowerMessage, "your credit balance is too low") ||
strings.Contains(lowerMessage, "this organization has been disabled") ||
strings.Contains(lowerMessage, "credit") ||
strings.Contains(lowerMessage, "balance") ||
strings.Contains(lowerMessage, "permission denied") ||
strings.Contains(lowerMessage, "已欠费") {
return true
}

return false
}

Expand Down

0 comments on commit 82f34d3

Please sign in to comment.