@@ -7,8 +7,11 @@ import {
77 shouldUseReasoningBudget ,
88 shouldUseReasoningEffort ,
99} from "../api"
10+ import { ANTHROPIC_DEFAULT_MAX_TOKENS } from "../../api/providers/constants"
1011
1112describe ( "getMaxTokensForModel" , ( ) => {
13+ const modelId = "test"
14+
1215 /**
1316 * Testing the specific fix in commit cc79178f:
1417 * For thinking models, use apiConfig.modelMaxTokens if available,
@@ -27,7 +30,7 @@ describe("getMaxTokensForModel", () => {
2730 modelMaxTokens : 4000 ,
2831 }
2932
30- expect ( getModelMaxOutputTokens ( { model, settings } ) ) . toBe ( 4000 )
33+ expect ( getModelMaxOutputTokens ( { modelId , model, settings } ) ) . toBe ( 4000 )
3134 } )
3235
3336 it ( "should return 16_384 for thinking models when modelMaxTokens not provided" , ( ) => {
@@ -40,7 +43,7 @@ describe("getMaxTokensForModel", () => {
4043
4144 const settings = { }
4245
43- expect ( getModelMaxOutputTokens ( { model, settings } ) ) . toBe ( 16_384 )
46+ expect ( getModelMaxOutputTokens ( { modelId , model, settings } ) ) . toBe ( 16_384 )
4447 } )
4548
4649 it ( "should return 16_384 for thinking models when apiConfig is undefined" , ( ) => {
@@ -51,7 +54,7 @@ describe("getMaxTokensForModel", () => {
5154 maxTokens : 8000 ,
5255 }
5356
54- expect ( getModelMaxOutputTokens ( { model, settings : undefined } ) ) . toBe ( 16_384 )
57+ expect ( getModelMaxOutputTokens ( { modelId , model, settings : undefined } ) ) . toBe ( 16_384 )
5558 } )
5659
5760 it ( "should return modelInfo.maxTokens for non-thinking models" , ( ) => {
@@ -65,7 +68,7 @@ describe("getMaxTokensForModel", () => {
6568 modelMaxTokens : 4000 ,
6669 }
6770
68- expect ( getModelMaxOutputTokens ( { model, settings } ) ) . toBe ( 8000 )
71+ expect ( getModelMaxOutputTokens ( { modelId , model, settings } ) ) . toBe ( 8000 )
6972 } )
7073
7174 it ( "should return undefined for non-thinking models with undefined maxTokens" , ( ) => {
@@ -78,7 +81,7 @@ describe("getMaxTokensForModel", () => {
7881 modelMaxTokens : 4000 ,
7982 }
8083
81- expect ( getModelMaxOutputTokens ( { model, settings } ) ) . toBeUndefined ( )
84+ expect ( getModelMaxOutputTokens ( { modelId , model, settings } ) ) . toBeUndefined ( )
8285 } )
8386
8487 test ( "should return maxTokens from modelInfo when thinking is false" , ( ) => {
@@ -92,7 +95,7 @@ describe("getMaxTokensForModel", () => {
9295 modelMaxTokens : 4096 ,
9396 }
9497
95- const result = getModelMaxOutputTokens ( { model, settings } )
98+ const result = getModelMaxOutputTokens ( { modelId , model, settings } )
9699 expect ( result ) . toBe ( 2048 )
97100 } )
98101
@@ -108,7 +111,7 @@ describe("getMaxTokensForModel", () => {
108111 modelMaxTokens : 4096 ,
109112 }
110113
111- const result = getModelMaxOutputTokens ( { model, settings } )
114+ const result = getModelMaxOutputTokens ( { modelId , model, settings } )
112115 expect ( result ) . toBe ( 4096 )
113116 } )
114117
@@ -122,7 +125,7 @@ describe("getMaxTokensForModel", () => {
122125
123126 const settings : ProviderSettings = { }
124127
125- const result = getModelMaxOutputTokens ( { model, settings : undefined } )
128+ const result = getModelMaxOutputTokens ( { modelId , model, settings : undefined } )
126129 expect ( result ) . toBe ( 16_384 )
127130 } )
128131
@@ -133,7 +136,7 @@ describe("getMaxTokensForModel", () => {
133136 maxTokens : 2048 ,
134137 }
135138
136- expect ( getModelMaxOutputTokens ( { model : modelInfoOnly , settings : undefined } ) ) . toBe ( 2048 )
139+ expect ( getModelMaxOutputTokens ( { modelId , model : modelInfoOnly , settings : undefined } ) ) . toBe ( 2048 )
137140 } )
138141
139142 test ( "should handle missing properties gracefully" , ( ) => {
@@ -147,15 +150,51 @@ describe("getMaxTokensForModel", () => {
147150 modelMaxTokens : 4096 ,
148151 }
149152
150- expect ( getModelMaxOutputTokens ( { model : modelInfoWithoutMaxTokens , settings } ) ) . toBe ( 4096 )
153+ expect ( getModelMaxOutputTokens ( { modelId , model : modelInfoWithoutMaxTokens , settings } ) ) . toBe ( 4096 )
151154
152155 const modelInfoWithoutThinking : ModelInfo = {
153156 contextWindow : 200_000 ,
154157 supportsPromptCache : true ,
155158 maxTokens : 2048 ,
156159 }
157160
158- expect ( getModelMaxOutputTokens ( { model : modelInfoWithoutThinking , settings : undefined } ) ) . toBe ( 2048 )
161+ expect ( getModelMaxOutputTokens ( { modelId, model : modelInfoWithoutThinking , settings : undefined } ) ) . toBe ( 2048 )
162+ } )
163+
164+ test ( "should return ANTHROPIC_DEFAULT_MAX_TOKENS for Anthropic models that support reasoning budget but aren't using it" , ( ) => {
165+ // Test case for models that support reasoning budget but enableReasoningEffort is false
166+ const anthropicModelId = "claude-sonnet-4-20250514"
167+ const model : ModelInfo = {
168+ contextWindow : 200_000 ,
169+ supportsPromptCache : true ,
170+ supportsReasoningBudget : true ,
171+ maxTokens : 64_000 , // This should be ignored
172+ }
173+
174+ const settings : ProviderSettings = {
175+ enableReasoningEffort : false , // Not using reasoning
176+ }
177+
178+ const result = getModelMaxOutputTokens ( { modelId : anthropicModelId , model, settings } )
179+ expect ( result ) . toBe ( ANTHROPIC_DEFAULT_MAX_TOKENS ) // Should be 8192, not 64_000
180+ } )
181+
182+ test ( "should return model.maxTokens for non-Anthropic models that support reasoning budget but aren't using it" , ( ) => {
183+ // Test case for non-Anthropic models - should still use model.maxTokens
184+ const geminiModelId = "gemini-2.5-flash-preview-04-17"
185+ const model : ModelInfo = {
186+ contextWindow : 1_048_576 ,
187+ supportsPromptCache : false ,
188+ supportsReasoningBudget : true ,
189+ maxTokens : 65_535 ,
190+ }
191+
192+ const settings : ProviderSettings = {
193+ enableReasoningEffort : false , // Not using reasoning
194+ }
195+
196+ const result = getModelMaxOutputTokens ( { modelId : geminiModelId , model, settings } )
197+ expect ( result ) . toBe ( 65_535 ) // Should use model.maxTokens, not ANTHROPIC_DEFAULT_MAX_TOKENS
159198 } )
160199} )
161200
0 commit comments