修复模型引用与账单展示

This commit is contained in:
2026-06-15 00:17:20 +08:00
parent 10ec25d87b
commit 02ba5d3cdd
6 changed files with 146 additions and 47 deletions
+23 -2
View File
@@ -867,7 +867,7 @@ func (s *Server) estimatePricing(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusBadRequest, "invalid json body")
return
}
model, _ := body["model"].(string)
model := requestModelName(body)
kind, _ := body["kind"].(string)
if kind == "" {
kind = "chat.completions"
@@ -997,7 +997,7 @@ func (s *Server) createTask(kind string, compatible bool) http.Handler {
writeError(w, status, err.Error(), clients.ErrorCode(err))
return
}
model, _ := body["model"].(string)
model := requestModelName(body)
if model == "" {
writeError(w, http.StatusBadRequest, "model is required")
return
@@ -1254,6 +1254,27 @@ func apiKeyScopeAllowed(user *auth.User, kind string) bool {
return false
}
func requestModelName(body map[string]any) string {
if body == nil {
return ""
}
return modelNameFromValue(body["model"])
}
func modelNameFromValue(value any) string {
switch typed := value.(type) {
case string:
return strings.TrimSpace(typed)
case map[string]any:
for _, key := range []string{"modelId", "model_id", "modelName", "model_name", "id", "name"} {
if model := modelNameFromValue(typed[key]); model != "" {
return model
}
}
}
return ""
}
func scopeForTaskKind(kind string) string {
switch kind {
case "chat.completions", "responses":