mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-12 03:13:41 +08:00
feat: able to fetch every request's cost
This commit is contained in:
@@ -59,7 +59,7 @@ func Relay(c *gin.Context) {
|
||||
group := c.GetString(ctxkey.Group)
|
||||
originalModel := c.GetString(ctxkey.OriginalModel)
|
||||
go processChannelRelayError(ctx, channelId, channelName, bizErr)
|
||||
requestId := c.GetString(logger.RequestIdKey)
|
||||
requestId := c.GetString(ctxkey.RequestId)
|
||||
retryTimes := config.RetryTimes
|
||||
if err := shouldRetry(c, bizErr.StatusCode); err != nil {
|
||||
logger.Errorf(ctx, "relay error happen, won't retry since of %v", err.Error())
|
||||
|
||||
@@ -16,6 +16,28 @@ import (
|
||||
"github.com/jinzhu/copier"
|
||||
)
|
||||
|
||||
func GetRequestCost(c *gin.Context) {
|
||||
reqId := c.Param("request_id")
|
||||
if reqId == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": "request_id 不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
docu, err := model.GetCostByRequestId(reqId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, docu)
|
||||
}
|
||||
|
||||
func GetAllTokens(c *gin.Context) {
|
||||
userId := c.GetInt(ctxkey.Id)
|
||||
p, _ := strconv.Atoi(c.Query("p"))
|
||||
|
||||
Reference in New Issue
Block a user