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,30 @@
|
||||
package limiter
|
||||
|
||||
import (
|
||||
"github.com/rose_cat707/luminary/internal/model"
|
||||
"github.com/rose_cat707/luminary/internal/store/cache"
|
||||
)
|
||||
|
||||
func IsProviderKeyAvailable(k model.ProviderKey) bool {
|
||||
if !k.Enabled {
|
||||
return false
|
||||
}
|
||||
if k.MaxRequestsPerDay > 0 && k.RequestsToday >= k.MaxRequestsPerDay {
|
||||
return false
|
||||
}
|
||||
if k.MaxTokensPerDay > 0 && k.TokensToday >= k.MaxTokensPerDay {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func CheckIngressBudget(k *model.IngressKey, estimatedCost float64) bool {
|
||||
if k.BudgetLimit <= 0 {
|
||||
return true
|
||||
}
|
||||
return k.BudgetUsed+estimatedCost <= k.BudgetLimit
|
||||
}
|
||||
|
||||
func CheckRateLimit(c *cache.Store, ingressKeyID uint, rpm, tpm, tokens int) bool {
|
||||
return c.CheckRateLimit(ingressKeyID, rpm, tpm, tokens)
|
||||
}
|
||||
Reference in New Issue
Block a user