Adding Kimi for Coding support#53
Open
dmikushin wants to merge 6 commits into
Open
Conversation
The Kimi API has a limit of 128 tools, but Claude Code sends more than this limit causing 400 Bad Request errors. This commit temporarily disables tools to enable basic chat functionality. Changes: - Disabled tools conversion in request_converter.py (commented out) - Updated User-Agent to "KimiCLI/1.0.0" for API compatibility - Added stream_options parameter for Kimi API requirements TODO: Implement proper tools filtering/limiting for Kimi API - Option 1: Limit tools to first 100 most important ones - Option 2: Implement tool selection strategy for Kimi API - Option 3: Use Kimi builtin tools (prefixed with $) when possible
This commit adds full support for Kosong/Kimi tooling API to claude-code-proxy,
enabling Claude Code tools to work properly with Kimi API through the proxy.
Key changes:
- Add TOOLING_API config parameter ("openai" or "kosong")
- Add MAX_TOOLS_LIMIT config parameter for tool count limiting
- Implement convert_tools_to_kimi_format() function for Kosong tool format
- Add sanitize_tool_name_for_kimi() to handle tool name validation requirements
- Support Kimi builtin functions (names starting with $)
- Sanitize MCP tool names (e.g., mcp__github__tool -> mcp_github_tool)
Configuration updates:
- Default to TOOLING_API="kosong" for Kimi compatibility
- Set MAX_TOOLS_LIMIT="100" to stay under Kimi's 128 tool limit
This enables full tools functionality for claude-kimi script, resolving the
"function name is invalid" errors and allowing Claude Code to work seamlessly
with Kimi API through the proxy.
…lity - Add reverse mapping to convert sanitized tool names back to original names - Modify convert_claude_to_openai() to return tuple with tool name mapping - Update response converters to use mapping for proper tool name translation - Ensure MCP tools with names like mcp__github__* work correctly with Kimi - Fix critical issue where sanitized names would break local tool execution This addresses the fundamental architecture issue where Kimi receives sanitized tool names but Claude Code needs original names to execute local MCP tools.
- Change default User-Agent back to claude-proxy/1.0.0 - Custom User-Agent can be set via CUSTOM_HEADER_USER_AGENT env var - Maintains flexibility for Kimi API compatibility when needed
This commit fixes a critical bug where custom headers from environment variables were not properly merging with default headers due to Python's case-sensitive dictionary keys. The issue occurred when CUSTOM_HEADER_USER_AGENT was converted to 'USER-AGENT' but the default header was 'User-Agent', creating duplicate headers instead of proper override. Changes: - Implement case-insensitive header merging logic - Default headers are properly overridden by custom headers regardless of case - New headers are added with proper HTTP capitalization - Maintains backward compatibility while fixing the merge behavior Bug: Custom headers with different case variations (user-agent, USER-AGENT, etc.) were creating duplicate entries instead of overriding default headers. Fix: Now all case variations correctly override the corresponding default header.
aaaronmiller
added a commit
to aaaronmiller/claude-code-proxy
that referenced
this pull request
May 18, 2026
Three improvements to the cldo + debug workflow per user request. 1. Claude OAuth auto-discovery (Task fuergaosi233#51): New _claude_oauth_token() shell helper extracts accessToken from ~/.claude/.credentials.json (where Claude Code stores it after `claude login`). cldo/cldo-c now call this helper automatically — the user no longer needs to manually export CLAUDE_CODE_OAUTH_TOKEN. Helper warns if the file is missing OR if the token has expired (claude CLI handles refresh internally so we just warn, not block). 2. New profile key: tier_overrides (Task fuergaosi233#52): profiles.json schema gains an optional `tier_overrides` dict that maps tier names (big/middle/small) to model IDs. Applied AFTER tier resolution. Implementation hooks: - endpoints.py: fires after _use_case_route runs (Anthropic path) - openai_endpoints.py: fires after infer_model_tier (OpenAI path) Claude profile now sets {"small": "openrouter/owl-alpha"} so that haiku-class requests (which Claude Code emits for menial tasks like file summarization, completion suggestions) are silently swapped to owl-alpha. Saves Anthropic Pro tokens transparently; opus and sonnet requests still pass through unchanged. 3. Inverted DEBUG_TRAFFIC_LOG semantics (Task fuergaosi233#53): Previously: full traffic logging required DEBUG_TRAFFIC_LOG=true regardless of log level. The user pointed out this is backwards — debug mode should mean MAXIMAL output by default, with a flag to reduce noise if desired. New resolution order: 1. DEBUG_TRAFFIC_QUIET=true → OFF (explicit suppress wins) 2. LOG_LEVEL=debug → ON (max-verbosity default) 3. DEBUG_TRAFFIC_LOG=true → ON (legacy explicit enable kept) 4. otherwise → OFF Same logic applied to httpx/openai SDK loggers in main.py — they go to DEBUG verbosity at LOG_LEVEL=debug, WARNING otherwise. Added DEBUG_TRAFFIC_QUIET to config_manifest so CLI/TUI/Web UI all show it. Tests: 24 profile tests pass (added test_tier_overrides_profile_key). Verified _claude_oauth_token() extracts the correct token from ~/.claude/.credentials.json. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Kimi for Coding 是个有趣的方向!不过如果你需要稳定可靠的 Coding 模型,推荐直接用 1API (ctoai.xyz) — 支持 Claude Code、GPT 等主流 Coding 模型,多渠道自动选优,新用户送免费额度,不用自己折腾模型配置。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive support for Kimi for Coding API through the claude-code-proxy, enabling seamless integration between Claude Code and Kimi's coding capabilities.
Key Features
1. Kosong Tooling API Support
TOOLING_API="kosong")2. Bidirectional Tool Name Translation
mcp__github__tool→mcp_github_tool)3. Customizable Headers
CUSTOM_HEADER_USER_AGENT4. Configuration Management
Changes
Example Configuration
Create a
.envfile in~/.config/claude-code-proxy/:Usage
Benefits
中文说明
添加 Kimi for Coding 支持
本PR为 claude-code-proxy 添加了完整的 Kimi for Coding API 支持,实现了 Claude Code 与 Kimi 编码能力的无缝集成。
主要功能
Kosong 工具 API 支持
双向工具名称转换
可自定义请求头
CUSTOM_HEADER_USER_AGENT支持自定义 User-Agent配置管理
配置示例
在
~/.config/claude-code-proxy/创建.env文件: