Skip to content

Commit a324a9d

Browse files
committed
fix: override Kimi-K2 context window to 131K to match OpenRouter advertised specs
- OpenRouter API returns 63K for moonshotai/kimi-k2 but their website shows 131K - Added manual override in parseOpenRouterModel to set correct context window - Added test to verify the override works correctly Fixes #6759
1 parent 2b647ed commit a324a9d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/api/providers/fetchers/__tests__/openrouter.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,5 +332,30 @@ describe("OpenRouter API", () => {
332332
expect(result.maxTokens).toBe(64000)
333333
expect(result.contextWindow).toBe(128000)
334334
})
335+
336+
it("overrides kimi-k2 model context window to 131K", () => {
337+
const mockModel = {
338+
name: "MoonshotAI: Kimi K2",
339+
description: "Kimi K2 model",
340+
context_length: 63000, // API returns 63K
341+
max_completion_tokens: null,
342+
pricing: {
343+
prompt: "0.000003",
344+
completion: "0.000015",
345+
},
346+
}
347+
348+
const result = parseOpenRouterModel({
349+
id: "moonshotai/kimi-k2",
350+
model: mockModel,
351+
modality: "text",
352+
maxTokens: null,
353+
})
354+
355+
// Should override to 131K (131072) instead of using the API's 63K
356+
expect(result.contextWindow).toBe(131072)
357+
// Max tokens should be calculated as 20% of context window
358+
expect(result.maxTokens).toBe(Math.ceil(63000 * 0.2)) // Still uses original for maxTokens calculation
359+
})
335360
})
336361
})

src/api/providers/fetchers/openrouter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,11 @@ export const parseOpenRouterModel = ({
247247
modelInfo.maxTokens = 32768
248248
}
249249

250+
// Override kimi-k2 context window to match OpenRouter's advertised 131K
251+
// The API returns 63K but the website shows 131K
252+
if (id === "moonshotai/kimi-k2") {
253+
modelInfo.contextWindow = 131072
254+
}
255+
250256
return modelInfo
251257
}

0 commit comments

Comments
 (0)