feat: add support for Grok-4 Fast model via OpenRouter and xAI

- Added grok-4-fast to xAI models configuration with free pricing
- Added special handling in OpenRouter fetcher to override pricing for free promotion
- Added tests for the new model in both xAI and OpenRouter test suites
- Model supports 256K context window and image inputs

Fixes #8217
This commit is contained in:
Roo Code 2025-09-22 16:32:19 +00:00
parent 6c2aa63cfd
commit 3c7cc59b7c
4 changed files with 61 additions and 0 deletions

View file

@ -17,6 +17,17 @@ export const xaiModels = {
cacheReadsPrice: 0.02,
description: "xAI's Grok Code Fast model with 256K context window",
},
"grok-4-fast": {
maxTokens: 8192,
contextWindow: 256000,
supportsImages: true,
supportsPromptCache: true,
inputPrice: 0.0, // Currently free on OpenRouter
outputPrice: 0.0, // Currently free on OpenRouter
cacheWritesPrice: 0.0,
cacheReadsPrice: 0.0,
description: "xAI's Grok-4 Fast model with 256K context window - currently free on OpenRouter",
},
"grok-4": {
maxTokens: 8192,
contextWindow: 256000,

View file

@ -69,6 +69,18 @@ describe("XAIHandler", () => {
expect(model.info).toEqual(xaiModels[testModelId])
})
test("should return grok-4-fast model when specified", () => {
const testModelId = "grok-4-fast"
const handlerWithModel = new XAIHandler({ apiModelId: testModelId })
const model = handlerWithModel.getModel()
expect(model.id).toBe(testModelId)
expect(model.info).toEqual(xaiModels[testModelId])
// Verify it's currently free
expect(model.info.inputPrice).toBe(0.0)
expect(model.info.outputPrice).toBe(0.0)
})
it("should include reasoning_effort parameter for mini models", async () => {
const miniModelHandler = new XAIHandler({
apiModelId: "grok-3-mini",

View file

@ -382,5 +382,34 @@ describe("OpenRouter API", () => {
expect(textResult.maxTokens).toBe(64000)
expect(imageResult.maxTokens).toBe(64000)
})
it("sets xai/grok-4-fast model to free pricing", () => {
const mockModel = {
name: "Grok 4 Fast",
description: "xAI's Grok-4 Fast model",
context_length: 256000,
max_completion_tokens: 8192,
pricing: {
prompt: "0.003",
completion: "0.015",
},
}
const result = parseOpenRouterModel({
id: "xai/grok-4-fast",
model: mockModel,
inputModality: ["text"],
outputModality: ["text"],
maxTokens: 8192,
})
// Should override pricing to free
expect(result.inputPrice).toBe(0.0)
expect(result.outputPrice).toBe(0.0)
expect(result.cacheWritesPrice).toBe(0.0)
expect(result.cacheReadsPrice).toBe(0.0)
expect(result.contextWindow).toBe(256000)
expect(result.maxTokens).toBe(8192)
})
})
})

View file

@ -263,5 +263,14 @@ export const parseOpenRouterModel = ({
modelInfo.maxTokens = 32768
}
// Set xai/grok-4-fast model configuration (currently free on OpenRouter)
if (id === "xai/grok-4-fast") {
// Override pricing to reflect current free promotion
modelInfo.inputPrice = 0.0
modelInfo.outputPrice = 0.0
modelInfo.cacheWritesPrice = 0.0
modelInfo.cacheReadsPrice = 0.0
}
return modelInfo
}