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.
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文件: