@@ -118,9 +118,18 @@ describe('Count Tokens', () => {
118118 } ;
119119 const response = await model . countTokens ( [ imagePart ] ) ;
120120
121+ let expectedImageTokens : number ;
122+ if ( testConfig . model === 'gemini-3-pro-preview' ) {
123+ expectedImageTokens =
124+ testConfig . ai . backend . backendType === BackendType . GOOGLE_AI
125+ ? 1089
126+ : 1120 ;
127+ } else {
128+ expectedImageTokens = 258 ;
129+ }
130+
121131 if ( testConfig . ai . backend . backendType === BackendType . GOOGLE_AI ) {
122- const expectedImageTokens = 259 ;
123- expect ( response . totalTokens ) . to . equal ( expectedImageTokens ) ;
132+ expect ( response . totalTokens ) . to . equal ( expectedImageTokens + 1 ) ; // There will be 1 unexpected text token
124133 expect ( response . totalBillableCharacters ) . to . be . undefined ; // Incorrect behavior
125134 expect ( response . promptTokensDetails ! . length ) . to . equal ( 2 ) ;
126135 expect ( response . promptTokensDetails ! [ 0 ] ) . to . deep . equal ( {
@@ -129,19 +138,18 @@ describe('Count Tokens', () => {
129138 } ) ;
130139 expect ( response . promptTokensDetails ! [ 1 ] ) . to . deep . equal ( {
131140 modality : Modality . IMAGE ,
132- tokenCount : 258
141+ tokenCount : expectedImageTokens
133142 } ) ;
134143 } else if (
135144 testConfig . ai . backend . backendType === BackendType . VERTEX_AI
136145 ) {
137- const expectedImageTokens = 258 ;
138146 expect ( response . totalTokens ) . to . equal ( expectedImageTokens ) ;
139147 expect ( response . totalBillableCharacters ) . to . be . undefined ; // Incorrect behavior
140148 expect ( response . promptTokensDetails ! . length ) . to . equal ( 1 ) ;
141149 // Note: No text tokens are present for Vertex AI with image-only input.
142150 expect ( response . promptTokensDetails ! [ 0 ] ) . to . deep . equal ( {
143151 modality : Modality . IMAGE ,
144- tokenCount : 258
152+ tokenCount : expectedImageTokens
145153 } ) ;
146154 expect ( response . promptTokensDetails ! [ 0 ] . tokenCount ) . to . equal (
147155 expectedImageTokens
@@ -220,13 +228,23 @@ describe('Count Tokens', () => {
220228 expect ( response . promptTokensDetails ) . to . exist ;
221229 expect ( response . promptTokensDetails ! . length ) . to . equal ( 3 ) ;
222230
231+ let expectedImageTokenCount ;
232+ if ( testConfig . model === 'gemini-3-pro-preview' ) {
233+ expectedImageTokenCount =
234+ testConfig . ai . backend . backendType === BackendType . GOOGLE_AI
235+ ? 1089
236+ : 1120 ;
237+ } else {
238+ expectedImageTokenCount = 258 ;
239+ }
240+
223241 expect ( imageDetails ) . to . deep . equal ( {
224242 modality : Modality . IMAGE ,
225- tokenCount : 258
243+ tokenCount : expectedImageTokenCount
226244 } ) ;
227245
228246 if ( testConfig . ai . backend . backendType === BackendType . GOOGLE_AI ) {
229- expect ( response . totalTokens ) . to . equal ( 267 ) ;
247+ expect ( response . totalTokens ) . to . equal ( expectedImageTokenCount + 9 ) ;
230248 expect ( response . totalBillableCharacters ) . to . be . undefined ;
231249 expect ( textDetails ) . to . deep . equal ( {
232250 modality : Modality . TEXT ,
@@ -239,7 +257,7 @@ describe('Count Tokens', () => {
239257 } else if (
240258 testConfig . ai . backend . backendType === BackendType . VERTEX_AI
241259 ) {
242- expect ( response . totalTokens ) . to . equal ( 261 ) ;
260+ expect ( response . totalTokens ) . to . equal ( expectedImageTokenCount + 3 ) ;
243261 expect ( textDetails ) . to . deep . equal ( {
244262 modality : Modality . TEXT ,
245263 tokenCount : 3
@@ -269,7 +287,12 @@ describe('Count Tokens', () => {
269287
270288 const response = await model . countTokens ( [ filePart ] ) ;
271289
272- const expectedFileTokens = 258 ;
290+ let expectedFileTokens : number ;
291+ if ( testConfig . model === 'gemini-3-pro-preview' ) {
292+ expectedFileTokens = 1120 ;
293+ } else {
294+ expectedFileTokens = 258 ;
295+ }
273296 expect ( response . totalTokens ) . to . equal ( expectedFileTokens ) ;
274297 expect ( response . totalBillableCharacters ) . to . be . undefined ;
275298 expect ( response . promptTokensDetails ) . to . exist ;
0 commit comments