diff --git a/api/models/tx.js b/api/models/tx.js index f3ba38652d..b6d627620a 100644 --- a/api/models/tx.js +++ b/api/models/tx.js @@ -135,10 +135,11 @@ const tokenValues = Object.assign( 'grok-2-1212': { prompt: 2.0, completion: 10.0 }, 'grok-2-latest': { prompt: 2.0, completion: 10.0 }, 'grok-2': { prompt: 2.0, completion: 10.0 }, - 'grok-3-mini-fast': { prompt: 0.4, completion: 4 }, + 'grok-3-mini-fast': { prompt: 0.6, completion: 4 }, 'grok-3-mini': { prompt: 0.3, completion: 0.5 }, 'grok-3-fast': { prompt: 5.0, completion: 25.0 }, 'grok-3': { prompt: 3.0, completion: 15.0 }, + 'grok-4': { prompt: 3.0, completion: 15.0 }, 'grok-beta': { prompt: 5.0, completion: 15.0 }, 'mistral-large': { prompt: 2.0, completion: 6.0 }, 'pixtral-large': { prompt: 2.0, completion: 6.0 }, diff --git a/api/models/tx.spec.js b/api/models/tx.spec.js index 1c886c1994..114b7b892d 100644 --- a/api/models/tx.spec.js +++ b/api/models/tx.spec.js @@ -636,6 +636,15 @@ describe('Grok Model Tests - Pricing', () => { ); }); + test('should return correct prompt and completion rates for Grok 4 model', () => { + expect(getMultiplier({ model: 'grok-4-0709', tokenType: 'prompt' })).toBe( + tokenValues['grok-4'].prompt, + ); + expect(getMultiplier({ model: 'grok-4-0709', tokenType: 'completion' })).toBe( + tokenValues['grok-4'].completion, + ); + }); + test('should return correct prompt and completion rates for Grok 3 models with prefixes', () => { expect(getMultiplier({ model: 'xai/grok-3', tokenType: 'prompt' })).toBe( tokenValues['grok-3'].prompt, @@ -662,6 +671,15 @@ describe('Grok Model Tests - Pricing', () => { tokenValues['grok-3-mini-fast'].completion, ); }); + + test('should return correct prompt and completion rates for Grok 4 model with prefixes', () => { + expect(getMultiplier({ model: 'xai/grok-4-0709', tokenType: 'prompt' })).toBe( + tokenValues['grok-4'].prompt, + ); + expect(getMultiplier({ model: 'xai/grok-4-0709', tokenType: 'completion' })).toBe( + tokenValues['grok-4'].completion, + ); + }); }); }); diff --git a/api/utils/tokens.js b/api/utils/tokens.js index 21608fddc6..a8363db182 100644 --- a/api/utils/tokens.js +++ b/api/utils/tokens.js @@ -223,6 +223,7 @@ const xAIModels = { 'grok-3-fast': 131072, 'grok-3-mini': 131072, 'grok-3-mini-fast': 131072, + 'grok-4': 256000, // 256K context }; const aggregateModels = { ...openAIModels, ...googleModels, ...bedrockModels, ...xAIModels }; diff --git a/api/utils/tokens.spec.js b/api/utils/tokens.spec.js index 4a34746e8b..8a2e8ed11d 100644 --- a/api/utils/tokens.spec.js +++ b/api/utils/tokens.spec.js @@ -386,7 +386,7 @@ describe('matchModelName', () => { }); it('should return the closest matching key for gpt-4-1106 partial matches', () => { - expect(matchModelName('something/gpt-4-1106')).toBe('gpt-4-1106'); + expect(matchModelName('gpt-4-1106/something')).toBe('gpt-4-1106'); expect(matchModelName('gpt-4-1106-preview')).toBe('gpt-4-1106'); expect(matchModelName('gpt-4-1106-vision-preview')).toBe('gpt-4-1106'); }); @@ -589,6 +589,10 @@ describe('Grok Model Tests - Tokens', () => { expect(getModelMaxTokens('grok-3-mini-fast')).toBe(131072); }); + test('should return correct tokens for Grok 4 model', () => { + expect(getModelMaxTokens('grok-4-0709')).toBe(256000); + }); + test('should handle partial matches for Grok models with prefixes', () => { // Vision models should match before general models expect(getModelMaxTokens('xai/grok-2-vision-1212')).toBe(32768); @@ -606,6 +610,8 @@ describe('Grok Model Tests - Tokens', () => { expect(getModelMaxTokens('xai/grok-3-fast')).toBe(131072); expect(getModelMaxTokens('xai/grok-3-mini')).toBe(131072); expect(getModelMaxTokens('xai/grok-3-mini-fast')).toBe(131072); + // Grok 4 model + expect(getModelMaxTokens('xai/grok-4-0709')).toBe(256000); }); }); @@ -627,6 +633,8 @@ describe('Grok Model Tests - Tokens', () => { expect(matchModelName('grok-3-fast')).toBe('grok-3-fast'); expect(matchModelName('grok-3-mini')).toBe('grok-3-mini'); expect(matchModelName('grok-3-mini-fast')).toBe('grok-3-mini-fast'); + // Grok 4 model + expect(matchModelName('grok-4-0709')).toBe('grok-4'); }); test('should match Grok model variations with prefixes', () => { @@ -646,6 +654,8 @@ describe('Grok Model Tests - Tokens', () => { expect(matchModelName('xai/grok-3-fast')).toBe('grok-3-fast'); expect(matchModelName('xai/grok-3-mini')).toBe('grok-3-mini'); expect(matchModelName('xai/grok-3-mini-fast')).toBe('grok-3-mini-fast'); + // Grok 4 model + expect(matchModelName('xai/grok-4-0709')).toBe('grok-4'); }); }); });