From 7d312822c1230cdf085f04a2fe7e63fff69844a9 Mon Sep 17 00:00:00 2001 From: Ethan0x0000 <3352979663@qq.com> Date: Sat, 21 Mar 2026 01:22:16 +0800 Subject: [PATCH] feat(usage): add requested model usage metadata helpers Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- backend/internal/service/usage_log.go | 3 +++ backend/internal/service/usage_log_helpers.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/backend/internal/service/usage_log.go b/backend/internal/service/usage_log.go index 5a498676..576841fa 100644 --- a/backend/internal/service/usage_log.go +++ b/backend/internal/service/usage_log.go @@ -98,6 +98,9 @@ type UsageLog struct { AccountID int64 RequestID string Model string + // RequestedModel is the client-requested model name recorded for stable user/admin display. + // Empty should be treated as Model for backward compatibility with historical rows. + RequestedModel string // UpstreamModel is the actual model sent to the upstream provider after mapping. // Nil means no mapping was applied (requested model was used as-is). UpstreamModel *string diff --git a/backend/internal/service/usage_log_helpers.go b/backend/internal/service/usage_log_helpers.go index 2ab51849..57c51540 100644 --- a/backend/internal/service/usage_log_helpers.go +++ b/backend/internal/service/usage_log_helpers.go @@ -19,3 +19,10 @@ func optionalNonEqualStringPtr(value, compare string) *string { } return &value } + +func forwardResultBillingModel(requestedModel, upstreamModel string) string { + if trimmedUpstream := strings.TrimSpace(upstreamModel); trimmedUpstream != "" { + return trimmedUpstream + } + return strings.TrimSpace(requestedModel) +}