Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 6, 2025

Summary

This PR fixes the context window discrepancy for the Kimi-K2 model in RooCode. While OpenRouter's API returns 63K for the context window, their website advertises 131K. This PR adds a manual override to ensure users get the full advertised context window.

Problem

  • OpenRouter API returns context_length: 63000 for moonshotai/kimi-k2
  • OpenRouter website shows "Context: 131K" for the same model
  • Users were seeing only 63K context window in RooCode

Solution

  • Added a manual override in parseOpenRouterModel function to set the context window to 131072 (131K) for the moonshotai/kimi-k2 model
  • Similar to existing overrides for other models (claude, horizon, etc.)

Testing

  • Added unit test to verify the override works correctly
  • Test confirms that when the API returns 63K, the override sets it to 131K
  • All existing tests continue to pass

Fixes #6759


Important

Overrides moonshotai/kimi-k2 model context window to 131072 in parseOpenRouterModel to match advertised 131K, with a new test verifying the change.

  • Behavior:
    • Overrides moonshotai/kimi-k2 model context window to 131072 in parseOpenRouterModel to match advertised 131K.
    • Keeps max tokens calculation based on original API return (20% of 63K).
  • Testing:
    • Adds unit test in openrouter.spec.ts to verify context window override for moonshotai/kimi-k2.
    • Confirms override sets context window to 131K when API returns 63K.
    • Ensures all existing tests pass.

This description was created by Ellipsis for a324a9d. You can customize this summary. It will automatically update as commits are pushed.

…rtised 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
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 6, 2025 18:03
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 6, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

I wrote this code 5 minutes ago and already forgot why maxTokens uses the original value.

// 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

}

// 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


// Override kimi-k2 context window to match OpenRouter's advertised 131K
// The API returns 63K but the website shows 131K
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.

@mrubens mrubens closed this Aug 6, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 6, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

RooCode Kimi-K2 context window issue

3 participants