MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / GetUsage

Function GetUsage

controller/billing.go:60–92  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

58}
59
60func GetUsage(c *gin.Context) {
61 var quota int
62 var err error
63 var token *model.Token
64 if common.DisplayTokenStatEnabled {
65 tokenId := c.GetInt("token_id")
66 token, err = model.GetTokenById(tokenId)
67 quota = token.UsedQuota
68 } else {
69 userId := c.GetInt("id")
70 quota, err = model.GetUserUsedQuota(userId)
71 }
72 if err != nil {
73 openAIError := dto.OpenAIError{
74 Message: err.Error(),
75 Type: "new_api_error",
76 }
77 c.JSON(200, gin.H{
78 "error": openAIError,
79 })
80 return
81 }
82 amount := float64(quota)
83 if common.DisplayInCurrencyEnabled {
84 amount /= common.QuotaPerUnit
85 }
86 usage := OpenAIUsageResponse{
87 Object: "list",
88 TotalUsage: amount * 100,
89 }
90 c.JSON(200, usage)
91 return
92}

Callers

nothing calls this directly

Calls 3

GetTokenByIdFunction · 0.92
GetUserUsedQuotaFunction · 0.92
ErrorMethod · 0.80

Tested by

no test coverage detected