Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/api/providers/fetchers/__tests__/openrouter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,30 @@ describe("OpenRouter API", () => {
expect(result.maxTokens).toBe(64000)
expect(result.contextWindow).toBe(128000)
})

it("overrides kimi-k2 model context window to 131K", () => {
const mockModel = {
name: "MoonshotAI: Kimi K2",
description: "Kimi K2 model",
context_length: 63000, // API returns 63K
max_completion_tokens: null,
pricing: {
prompt: "0.000003",
completion: "0.000015",
},
}

const result = parseOpenRouterModel({
id: "moonshotai/kimi-k2",
model: mockModel,
modality: "text",
maxTokens: null,
})

// Should override to 131K (131072) instead of using the API's 63K
expect(result.contextWindow).toBe(131072)
// Max tokens should be calculated as 20% of context window
expect(result.maxTokens).toBe(Math.ceil(63000 * 0.2)) // Still uses original for maxTokens calculation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? The test comment mentions "Still uses original for maxTokens calculation", but it might be confusing that the context window is overridden to 131K while maxTokens remains based on the original 63K (20% of 63K = 12,600). Consider either:

  • Using 20% of the new 131K context window for consistency
  • Adding a comment in the implementation explaining why maxTokens uses the original value

})
})
})
6 changes: 6 additions & 0 deletions src/api/providers/fetchers/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,11 @@ export const parseOpenRouterModel = ({
modelInfo.maxTokens = 32768
}

// Override kimi-k2 context window to match OpenRouter's advertised 131K
// The API returns 63K but the website shows 131K
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be helpful to add a link to the OpenRouter website page as a reference? For example:

Suggested change
// The API returns 63K but the website shows 131K
// Override kimi-k2 context window to match OpenRouter's advertised 131K
// The API returns 63K but the website shows 131K
// See: https://openrouter.ai/moonshotai/kimi-k2

if (id === "moonshotai/kimi-k2") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this override closer to other model-specific overrides (lines 236-248) for better code organization and consistency with the existing pattern.

modelInfo.contextWindow = 131072
}

return modelInfo
}
Loading