Skip to content

fix: show upstream model in user usage records when model mapping is applied#1454

Open
octo-patch wants to merge 2 commits intoWei-Shaw:mainfrom
octo-patch:fix/issue-1444-show-upstream-model-for-users
Open

fix: show upstream model in user usage records when model mapping is applied#1454
octo-patch wants to merge 2 commits intoWei-Shaw:mainfrom
octo-patch:fix/issue-1444-show-upstream-model-for-users

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #1444

Problem

When a model mapping is configured (e.g., GPT-5.3-codex → GPT-5.4-mini), the usage records shown to regular users only display the originally requested model name (GPT-5.3-codex), making it impossible to see which model was actually used. The upstream_model field was available in the database and shown in admin views, but excluded from user-facing API responses.

Solution

  • Added upstream_model field to the user-facing UsageLog DTO (previously it was admin-only)
  • Populated UpstreamModel in usageLogFromServiceUser() from the service layer
  • Updated UsageView.vue to display the mapped model below the requested model with an arrow indicator (↳) when a mapping was applied
  • Updated UserDashboardRecentUsage.vue to also show the mapped model in the dashboard recent usage list
  • Moved UpstreamModel from AdminUsageLog into the base UsageLog struct since it's now shared
  • Updated the test to reflect the new behavior

Testing

  • Unit test TestUsageLogFromService_UsesRequestedModelAndIncludesUpstreamModel updated to verify upstream_model is now included in both user and admin JSON responses
  • When no mapping is applied, upstream_model is omitted (omitempty), so the display is unchanged for unmapped requests

… gateway (fixes Wei-Shaw#1430)

When a GPT account's model mapping uses a non-standard name (e.g. "gpt"
without version), RecordUsage could not find pricing and silently billed
zero. Similarly, the Anthropic Messages compat path set BillingModel to
the correct GPT model but RecordUsage ignored it, billing at Claude rates
instead.

Two changes to OpenAIGatewayService.RecordUsage:
1. Prefer result.BillingModel when set (non-empty), falling back to the
   existing forwardResultBillingModel logic. This ensures the Messages
   compat path (CC to GPT) uses the correct GPT pricing.
2. When the resolved billing model has no pricing configured, fall back
   to result.UpstreamModel before giving up. The upstream model is always
   normalised to a known model (e.g. "gpt-5.1"), so this prevents
   billing from silently dropping to zero for non-standard model names.
…ing is applied (fixes Wei-Shaw#1444)

Previously, users could not see which model was actually used when model
mapping was configured. The upstream_model field was only included in
admin API responses. This change:

- Adds upstream_model to the user-facing UsageLog DTO
- Populates it from the service layer in usageLogFromServiceUser()
- Updates UsageView.vue to display the mapped model (e.g. GPT-5.3-codex then GPT-5.4-mini)
- Updates UserDashboardRecentUsage.vue to show the mapped model in the dashboard
- Updates test to reflect the new behavior

Co-Authored-By: Octopus <liyuan851277048@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

为什么我将 GPT-5.3-codex 映射到 GPT-5.4-mini,为什么我调用后使用记录里展示的还是使用GPT-5.3-codex

1 participant