fix: estimate image gen tokens from prompt length instead of hardcoding
CI / Lint (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Build (push) Has been cancelled

This commit is contained in:
2026-04-27 10:28:39 -04:00
parent 5ee539d95c
commit b1a72f5a10
+8 -2
View File
@@ -558,10 +558,16 @@ func (s *Server) handleImageGenerations(c *gin.Context) {
return return
} }
// Estimate tokens from prompt text (~4 chars per token)
promptTokens := uint32(len(req.Prompt) / 4)
if promptTokens < 1 {
promptTokens = 1
}
s.logRequest(startTime, clientID, providerName, req.Model, &models.Usage{ s.logRequest(startTime, clientID, providerName, req.Model, &models.Usage{
PromptTokens: 1, PromptTokens: promptTokens,
CompletionTokens: uint32(len(resp.Data)), CompletionTokens: uint32(len(resp.Data)),
TotalTokens: 1 + uint32(len(resp.Data)), TotalTokens: promptTokens + uint32(len(resp.Data)),
}, nil, false) }, nil, false)
c.JSON(http.StatusOK, resp) c.JSON(http.StatusOK, resp)