OpenAI-compatible AI gateway with Vue admin UI, multi-provider egress, ingress key governance, monitoring, and security controls. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package gateway
|
||||
|
||||
import "net/http"
|
||||
|
||||
// retryableUpstreamStatus reports HTTP codes that should trigger retry / failover.
|
||||
func retryableUpstreamStatus(code int) bool {
|
||||
switch code {
|
||||
case http.StatusTooManyRequests,
|
||||
http.StatusRequestTimeout,
|
||||
http.StatusBadGateway,
|
||||
http.StatusServiceUnavailable,
|
||||
http.StatusGatewayTimeout:
|
||||
return true
|
||||
default:
|
||||
return code >= 500
|
||||
}
|
||||
}
|
||||
|
||||
// tryNextKeyOnUpstreamStatus reports auth/rate errors where another provider key may work.
|
||||
func tryNextKeyOnUpstreamStatus(code int) bool {
|
||||
switch code {
|
||||
case http.StatusUnauthorized,
|
||||
http.StatusForbidden,
|
||||
http.StatusTooManyRequests,
|
||||
http.StatusPaymentRequired:
|
||||
return true
|
||||
default:
|
||||
return retryableUpstreamStatus(code)
|
||||
}
|
||||
}
|
||||
|
||||
// passThroughUpstreamStatus reports client errors that should be returned as-is.
|
||||
func passThroughUpstreamStatus(code int) bool {
|
||||
switch code {
|
||||
case http.StatusBadRequest,
|
||||
http.StatusNotFound,
|
||||
http.StatusUnprocessableEntity,
|
||||
http.StatusUnsupportedMediaType:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user