feat: improve model rate limit tracking

This commit is contained in:
2026-05-12 03:22:29 +08:00
parent 05632172d0
commit ba850a06c6
25 changed files with 1223 additions and 96 deletions
+19
View File
@@ -5,6 +5,7 @@ import (
"strings"
"github.com/easyai/easyai-ai-gateway/apps/api/internal/auth"
"github.com/easyai/easyai-ai-gateway/apps/api/internal/clients"
"github.com/easyai/easyai-ai-gateway/apps/api/internal/store"
)
@@ -108,3 +109,21 @@ func estimateRequestTokens(body map[string]any) int {
}
return len([]rune(text))/4 + 1
}
func tokenUsageAmounts(usage clients.Usage) map[string]float64 {
out := map[string]float64{}
if usage.InputTokens > 0 {
out["tpm_input"] = float64(usage.InputTokens)
}
if usage.OutputTokens > 0 {
out["tpm_output"] = float64(usage.OutputTokens)
}
total := usage.TotalTokens
if total <= 0 {
total = usage.InputTokens + usage.OutputTokens
}
if total > 0 {
out["tpm_total"] = float64(total)
}
return out
}