Files
renjue 76ba500417
CI / docker (push) Successful in 2m4s
Initial commit: Luminary AI Gateway
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>
2026-06-23 21:46:16 +08:00

31 lines
731 B
Go

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)
}