From 747dff5b76cea556d69e8ab95a5dbff81010618c Mon Sep 17 00:00:00 2001 From: JianFeeeee Date: Wed, 26 Aug 2026 20:28:20 +0800 Subject: [PATCH] fix(gateway): record actual served model for image requests handleImage recorded the raw request model id, so AUTO image generations showed up as model=AUTO in the request records and by-model aggregates instead of the image model actually served (e.g. Kwai-Kolors/Kolors). UnifiedResponse gains an optional Model field; Provider.Image fills it with the resolved id (AUTO resolves to the source's best image model), and handleImage prefers it when writing the audit record. --- internal/gateway/chat.go | 3 +++ internal/provider/provider.go | 2 ++ internal/types/types.go | 1 + 3 files changed, 6 insertions(+) diff --git a/internal/gateway/chat.go b/internal/gateway/chat.go index 71f43a6..5fd9821 100644 --- a/internal/gateway/chat.go +++ b/internal/gateway/chat.go @@ -932,6 +932,9 @@ func (g *Gateway) handleImage(w http.ResponseWriter, r *http.Request) { if usedSrc != "" { rec.Source = usedSrc } + if resp.Model != "" { + rec.Model = resp.Model // record the actual model served, not the raw request id + } rec.OK = true rec.Status = http.StatusOK rec.Compl = int64(len(resp.ImageData)) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 8803677..d3912db 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -988,6 +988,7 @@ func (p *Provider) Image(ctx context.Context, req *types.ImageGenRequest) (*type unified, terr := p.vm.Transform(p.adapter+"_image", "transform_response", raw) if terr == nil && unified != raw { if err := json.Unmarshal([]byte(unified), &out); err == nil { + out.Model = model // actual model served (AUTO resolved to bestImageModel) p.RecordSuccess(model) return &out, nil } @@ -1000,6 +1001,7 @@ func (p *Provider) Image(ctx context.Context, req *types.ImageGenRequest) (*type return nil, fmt.Errorf("unmarshal image response: %w", err) } out.ImageData = img.Data + out.Model = model // actual model served (AUTO resolved to bestImageModel) p.RecordSuccess(model) return &out, nil } diff --git a/internal/types/types.go b/internal/types/types.go index 1f0d7d1..7e49c5f 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -71,6 +71,7 @@ type ToolCall struct { // ---- Unified internal representation (what adapters produce) ---- type UnifiedResponse struct { + Model string `json:"model,omitempty"` Content string `json:"content"` ReasoningContent string `json:"reasoning_content,omitempty"` FinishReason string `json:"finish_reason,omitempty"`