Skip to content

fix(provider): add kimi-for-coding custom handler and fix model detection for k2p6 (Kimi K2.6) - #28080

Closed
herjarsa wants to merge 2 commits into
anomalyco:devfrom
herjarsa:fix/kimi-for-coding-k2p6-model-detection
Closed

herjarsa wants to merge 2 commits into
anomalyco:devfrom
herjarsa:fix/kimi-for-coding-k2p6-model-detection

Conversation

@herjarsa

Copy link
Copy Markdown

Issue for this PR

Closes #23933

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The kimi-for-coding provider registers Kimi K2.6 with model ID k2p6, but several code paths fail to properly handle this provider/model combination, causing the model to not be detected or function correctly with the plan agent and other subagents.

Four issues fixed:

  1. Missing custom provider handler (provider.ts): Unlike anthropic, the kimi-for-coding provider had no custom handler in the custom() function. This meant no anthropic-beta headers were sent for thinking streaming and tool-streaming features. Added a handler identical to anthropics that sets the required anthropic-beta headers.

  2. System prompt not matched (system.ts): The Kimi system prompt detection checks model.api.id.toLowerCase().includes("kimi"), but the model ID is k2p6 (not containing "kimi"). Added model.providerID === "kimi-for-coding" fallback so the Kimi-specific system prompt is used.

  3. Temperature/topP transforms not applied (transform.ts): The temperature function checks id.includes("kimi-k2") which doesnt match the k2p6 model ID. Added id.includes("k2p") fallback. Similarly added k2p6 to the topP model list.

  4. Schema sanitization not applied (transform.ts): The schema sanitization condition checks model.providerID === "moonshotai" || model.api.id.toLowerCase().includes("kimi"). Added model.providerID === "kimi-for-coding" so the same Moonshot schema fixes apply to Kimi-for-Coding.

The kimi-for-coding provider uses the @ai-sdk/anthropic SDK and routes to https://api.kimi.com/coding/v1. Its model k2p6 (display name "Kimi K2.6") was already registered in the models.dev catalog and bundled snapshot but lacked proper integration in the OpenCode provider layer.

How did you verify your code works?

  • All changes are type-safe and follow existing patterns in the codebase
  • The kimi-for-coding handler mirrors the anthropic handler pattern (lines 151-159)
  • The system prompt fix follows the same model.providerID check pattern used elsewhere
  • The transform fixes extend existing pattern matching to include the k2p6 model ID
  • The thinking enablement transform (line 1102-1112) already correctly matches k2p in model IDs so no change needed there

Screenshots / recordings

N/A - no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…detection

The kimi-for-coding provider registers Kimi K2.6 with model ID k2p6, but several code paths fail to properly handle this provider/model combination.

Fixes:
1. Add custom kimi-for-coding handler in provider.ts with anthropic-beta headers
2. Fix Kimi system prompt detection in system.ts to check providerID
3. Fix temperature/topP transforms in transform.ts for k2p6 model ID
4. Fix schema sanitization condition in transform.ts for kimi-for-coding
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

One potentially related PR found:

PR #27903: "fix(opencode): set KimiCLI/1.5 User-Agent for kimi-for-coding provider"
#27903

This PR also addresses the kimi-for-coding provider, though it focuses specifically on User-Agent headers. It may be worth reviewing to ensure both PRs address complementary aspects of the kimi-for-coding integration without overlap.

@herjarsa

Copy link
Copy Markdown
Author

Regarding the related PR #27903 (User-Agent header fix): these two PRs address complementary aspects of the kimi-for-coding integration with no overlap.

Both PRs improve kimi-for-coding support independently and can be merged in any order.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No model Kimi K2.6

1 participant