Skip to content

Commit 8447670

Browse files
authored
Fix incorrect reserved tokens calculation on OpenRouter (RooCodeInc#3626)
fix: improve token reservation logic in calculateTokenDistribution
1 parent b69825b commit 8447670

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

webview-ui/src/utils/model-utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export const calculateTokenDistribution = (
100100

101101
// Get the actual max tokens value from the model
102102
// If maxTokens is valid, use it, otherwise reserve 20% of the context window as a default
103-
const reservedForOutput = maxTokens && maxTokens > 0 ? maxTokens : Math.ceil(safeContextWindow * 0.2)
103+
const reservedForOutput =
104+
maxTokens && maxTokens > 0 && maxTokens !== safeContextWindow ? maxTokens : Math.ceil(safeContextWindow * 0.2)
104105

105106
// Calculate sizes directly without buffer display
106107
const availableSize = Math.max(0, safeContextWindow - safeContextTokens - reservedForOutput)

0 commit comments

Comments
 (0)