Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions setting/ratio_setting/model_ratio.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,15 @@ func FormatMatchingModelName(name string) string {
if strings.HasPrefix(name, "gpt-4o-gizmo") {
name = "gpt-4o-gizmo-*"
}

// Strip reasoning effort suffixes for pricing
reasoningSuffixes := []string{"-high", "-minimal", "-low", "-medium", "-none", "-xhigh"}
for _, suffix := range reasoningSuffixes {
if strings.HasSuffix(name, suffix) {
name = strings.TrimSuffix(name, suffix)
break
}
}
Comment on lines +837 to +845

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's understand the context better
head -c 10000 setting/ratio_setting/model_ratio.go | wc -l

Repository: QuantumNous/new-api

Length of output: 66


🏁 Script executed:

# Check the file size and examine the specific lines
wc -l setting/ratio_setting/model_ratio.go

Repository: QuantumNous/new-api

Length of output: 103


🏁 Script executed:

# Examine the code around lines 837-845
sed -n '820,860p' setting/ratio_setting/model_ratio.go

Repository: QuantumNous/new-api

Length of output: 1374


🏁 Script executed:

# Search for models ending with reasoning suffixes
echo "=== Models ending with reasoning suffixes in model_ratio.go ==="
rg -n '^\s*"[^"]*-(high|minimal|low|medium|none|xhigh)"\s*:' setting/ratio_setting/model_ratio.go

Repository: QuantumNous/new-api

Length of output: 451


🏁 Script executed:

# Check if corresponding base models exist
echo "=== Checking for base models (without suffixes) ==="
rg -n '^\s*"[^"]+":\s*\{' setting/ratio_setting/model_ratio.go | head -20

Repository: QuantumNous/new-api

Length of output: 114


🏁 Script executed:

# Look at the function this code is in to understand the usage
sed -n '800,850p' setting/ratio_setting/model_ratio.go

Repository: QuantumNous/new-api

Length of output: 1649


🏁 Script executed:

# Check if "yi" base model exists in pricing
rg -n '"yi"' setting/ratio_setting/model_ratio.go

Repository: QuantumNous/new-api

Length of output: 45


🏁 Script executed:

# Get more context around yi-medium definition
sed -n '220,230p' setting/ratio_setting/model_ratio.go

Repository: QuantumNous/new-api

Length of output: 505


🏁 Script executed:

# Search for all -medium, -high, -low models to identify false positives
rg -n '^\s*"[^"]*-(medium|high|low|minimal|none|xhigh)"\s*:' setting/ratio_setting/model_ratio.go

Repository: QuantumNous/new-api

Length of output: 387


🏁 Script executed:

# Check where FormatMatchingModelName is called from
rg -n 'FormatMatchingModelName' setting/ratio_setting/model_ratio.go

Repository: QuantumNous/new-api

Length of output: 411


🏁 Script executed:

# Check if yi-medium has specific pricing
rg -n 'yi-medium' setting/ratio_setting/model_ratio.go -B 2 -A 2

Repository: QuantumNous/new-api

Length of output: 397


🏁 Script executed:

# Search for ALL models ending with -medium, -high, -low, -minimal, -none, -xhigh in both maps
echo "=== All models in defaultModelPrice ending with reasoning suffixes ==="
rg -n '^\s*"[^"]*-(medium|high|low|minimal|none|xhigh)"' setting/ratio_setting/model_ratio.go | head -50

Repository: QuantumNous/new-api

Length of output: 458


🏁 Script executed:

# Check what models are defined starting with "yi" to see if there's a base yi
rg -n '"yi[^"]*"' setting/ratio_setting/model_ratio.go | head -30

Repository: QuantumNous/new-api

Length of output: 622


🏁 Script executed:

# Check the calls to FormatMatchingModelName in context to understand the impact
sed -n '410,415p' setting/ratio_setting/model_ratio.go

Repository: QuantumNous/new-api

Length of output: 182


🏁 Script executed:

# Understand the complete picture - check GetModelPrice function
sed -n '400,420p' setting/ratio_setting/model_ratio.go

Repository: QuantumNous/new-api

Length of output: 536


Fix suffix-stripping logic to avoid breaking legitimate model names.

The suffix-stripping logic breaks pricing lookup for legitimate models that end with reasoning-effort suffixes. Specifically, yi-medium gets normalized to yi, which doesn't exist in the pricing map, causing lookup failures.

The issue is that the logic strips suffixes from ANY model, not just reasoning-effort variants. The o3-mini variants work because they're explicitly defined with each suffix variant, but models like yi-medium are legitimate standalone models with their own pricing and should not be normalized.

Fix: Only strip reasoning-effort suffixes from models that support reasoning (e.g., o3-mini variants), or verify the base model exists in the pricing map before stripping. Otherwise, add explicit model entries for the non-suffixed variants, or use a more selective approach that doesn't affect existing models.

🤖 Prompt for AI Agents
In setting/ratio_setting/model_ratio.go around lines 837 to 845, the current
loop strips reasoning-effort suffixes from any model name, which incorrectly
normalizes legitimate model names like "yi-medium"; change the logic to first
check whether the base model (name with the suffix removed) exists in the
pricing map (or in a whitelist of models that support reasoning variants) before
trimming: only assign name = strings.TrimSuffix(name, suffix) if the pricing map
contains the base key (or the model is in the supported-variants list);
otherwise leave the original name unchanged so standalone models keep their
pricing lookup working.

return name
}

Expand Down