Skip to content

feat(providers): add Kimi (Moonshot AI) provider support#71

Closed
aispatialomics wants to merge 1 commit into
cafferychen777:mainfrom
aispatialomics:main
Closed

feat(providers): add Kimi (Moonshot AI) provider support#71
aispatialomics wants to merge 1 commit into
cafferychen777:mainfrom
aispatialomics:main

Conversation

@aispatialomics

Copy link
Copy Markdown
Contributor

Add native Kimi provider via Anthropic-compatible Messages API:

  • New KimiProcessor class and process_kimi() handler (R + Python)
  • get_provider() recognizes kimi-* and moonshot* model prefixes
  • Default endpoint https://api.kimi.com/coding/v1/messages
  • API key read from KIMI_API_KEY environment variable
  • KimiProcessor.extract_usage() and process_kimi(usage_sink=) support the token-usage capture introduced in 2.0.6

Adapted to the 2.0.6 provider-registry refactor (shared built-in pattern constant plus dispatch table with consistency checks on both the R and Python sides).

Description

What does this PR do?

Why is this change needed?

Related Issues

  • Fixes #
  • Related to #

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test improvements
  • Refactoring (no functional changes)
  • Performance improvement

Testing

  • All existing tests pass
  • New tests added for changes
  • Tested with real data (if applicable)

Test Environment:

  • R/Python Version:
  • Operating System:

Checklist

  • Code follows the project's coding standards
  • Self-review of the code completed
  • Documentation updated if needed
  • No API keys or sensitive data exposed
  • I have read and agree to the Contributing Guidelines

Add native Kimi provider via Anthropic-compatible Messages API:
- New KimiProcessor class and process_kimi() handler (R + Python)
- get_provider() recognizes kimi-* and moonshot* model prefixes
- Default endpoint https://api.kimi.com/coding/v1/messages
- API key read from KIMI_API_KEY environment variable
- KimiProcessor.extract_usage() and process_kimi(usage_sink=) support
  the token-usage capture introduced in 2.0.6

Adapted to the 2.0.6 provider-registry refactor (shared built-in
pattern constant plus dispatch table with consistency checks on both
the R and Python sides).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@cafferychen777 cafferychen777 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for adding Kimi support. The direction is welcome, but the current implementation mixes two different Kimi products and is based on provider-dispatch code that has since changed on main. Please update the PR before merge.

  1. Target one API product consistently

For mLLMCelltype, please target the Kimi Open Platform rather than the Kimi Code membership endpoint:

  • Endpoint: https://api.moonshot.cn/v1/chat/completions
  • Authentication: Authorization: Bearer <MOONSHOT_API_KEY>
  • Default model: kimi-k2.6
  • Model prefixes: kimi- and moonshot-
  • Protocol: OpenAI-compatible Chat Completions

The current combination of https://api.kimi.com/coding/v1/messages with kimi-k2.7 and moonshot-v1-8k is not a valid contract. The Kimi Code endpoint uses separate credentials and accepts kimi-for-coding or kimi-for-coding-highspeed; the Open Platform uses api.moonshot.cn and models such as kimi-k2.6 and moonshot-v1-*.

Official references:

If Kimi Code support is also desired, please implement it later as a separate kimi_code provider so its endpoint, credentials, and model IDs cannot be mixed with Open Platform requests.

  1. Rebase onto the latest main and follow the current registries

The PR currently conflicts with main in the R registry/dispatch files and in Python dispatch construction.

For R:

  • Add one kimi entry to .BUILTIN_PROVIDER_SPECS with the pattern, KimiProcessor, and display name.
  • Implement a thin KimiProcessor that reuses private$post_chat_completions_request() and private$extract_chat_completions_content().
  • Remove process_kimi.R.
  • Do not restore get_builtin_provider_processors().
  • Do not add another provider-name map to BaseAPIProcessor; display names are derived from .BUILTIN_PROVIDER_SPECS.

For Python:

  • Add the provider configuration in config.py.
  • Export process_kimi from providers/__init__.py.
  • Implement process_kimi using the existing build_chat_completions_body() and call_openai_compatible_api() helpers.
  • Do not manually edit the dispatch map in functions.py; the current runtime registry is built and validated automatically.

This should make Kimi a small provider-specific wrapper instead of duplicating the Anthropic implementation in both languages.

  1. Add provider-specific tests

Please add tests for both Python and R covering:

  • provider detection for kimi-k2.6 and moonshot-v1-8k
  • default model, endpoint, and API-key environment variable
  • request URL, Bearer header, model, messages, and thinking policy
  • response parsing and normalized usage
  • custom endpoint handling
  • malformed/error responses
  • registry consistency

The existing test suites pass, but no current test exercises the new Kimi code. In the present PR, python/mllmcelltype/providers/kimi.py is only 25% covered.

  1. Keep release history accurate

Version 2.0.6 has already been released. Please put this feature under the next development-version NEWS section rather than adding it retroactively to the 2.0.6 release notes.

After the rebase and rewrite, please run:

  • cd python && ruff check mllmcelltype tests
  • cd python && pytest --cov=mllmcelltype tests/
  • cd R && Rscript -e "devtools::test()"

Please also complete the PR description and testing checklist with the actual environment and results. Once these changes are pushed, I will review the updated implementation again.

@aispatialomics aispatialomics closed this by deleting the head repository Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants