← 返回 Skills 市场
mark-heartflow

Claude Code Custom Model Proxy

作者 mark-HeartFlow · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
79
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install claude-code-custom-model-proxy
功能描述
Configure Claude Code to work with custom model providers (like MiniMax, OpenAI-compatible APIs). This skill should be used when users want to: use Claude Co...
使用说明 (SKILL.md)

Claude Code Custom Model Proxy

This skill helps configure Claude Code to work with custom model providers that use OpenAI API format (like MiniMax) by setting up a proxy server that converts between Anthropic Messages API and OpenAI Chat Completions API.

When to Use This Skill

  • User wants to use Claude Code with a custom model provider (not Anthropic)
  • User's model provider uses OpenAI Chat Completions API format
  • User sees errors like "There's an issue with the selected model" in Claude Code
  • User needs to convert between Anthropic API format and OpenAI API format

Overview

Claude Code uses Anthropic Messages API format (/v1/messages), but many custom model providers (like MiniMax) use OpenAI Chat Completions API format (/v1/chat/completions). This skill provides a Python proxy server that:

  1. Listens on http://127.0.0.1:4002
  2. Accepts Anthropic API format requests from Claude Code
  3. Converts to OpenAI API format
  4. Forwards to the upstream provider
  5. Converts responses back to Anthropic SSE format
  6. Handles model validation, URL query strings, and UTF-8 encoding

Quick Start

1. Configure Claude Code

Create or edit ~/.claude/settings.json:

{
  "env": {
    "ANTHROPIC_BASE_URL": "http://127.0.0.1:4002",
    "ANTHROPIC_API_KEY": "fake-key-not-needed"
  }
}

Or use environment variables:

export ANTHROPIC_BASE_URL="http://127.0.0.1:4002"
export ANTHROPIC_API_KEY="fake-key"

2. Start the Proxy Server

python3 ~/.workbuddy/skills/claude-code-custom-model-proxy/scripts/claude_code_proxy.py

Or run in background:

nohup python3 ~/.workbuddy/skills/claude-code-custom-model-proxy/scripts/claude_code_proxy.py > /tmp/claude_proxy.log 2>&1 &

3. Start Claude Code

claude --model sonnet

Proxy Server Configuration

Edit scripts/claude_code_proxy.py to configure:

  • UPSTREAM_HOST: Your provider's API host (e.g., "api.53hk.cn")
  • UPSTREAM_PATH: API path (e.g., "/v1/chat/completions")
  • API_KEY: Your provider's API key
  • LISTEN_PORT: Proxy listen port (default: 4002)
  • Forced model name (line 44): Change "MiniMax-M2.7-highspeed" to your model

Common Issues and Solutions

Issue 1: "There's an issue with the selected model"

Cause: Claude Code validates model names locally before connecting to the API.

Solution: The proxy's GET /v1/models endpoint must return the model name Claude Code expects.

For --model sonnet, Claude Code expects claude-sonnet-4-6 in the models list.

The proxy already includes common model names in its response. Add more if needed:

models = {
    "data": [
        {"type": "model", "id": "claude-sonnet-4-6", "display_name": "Claude Sonnet 4.6"},
        {"type": "model", "id": "claude-opus-4-5", "display_name": "Claude Opus 4.5"},
        # Add more models as needed
    ]
}

Issue 2: 404 errors in proxy logs

Cause: Claude Code sends requests with query strings (e.g., POST /v1/messages?beta=true), but the proxy only checks self.path == "/v1/messages".

Solution: The proxy now uses urlparse() to extract the path without query string:

from urllib.parse import urlparse

parsed_path = urlparse(self.path)
path = parsed_path.path  # This removes ?beta=true

Issue 3: Chinese characters appear as garbled text (乱码)

Cause: Incorrect handling of UTF-8 encoding in SSE streaming.

Solution: Use byte buffer instead of string buffer:

buffer = b""  # Byte buffer
for chunk in r.iter_content(chunk_size=None, decode_unicode=False):
    if chunk:
        buffer += chunk
        while b"\
" in buffer:
            line_bytes, buffer = buffer.split(b"\
", 1)
            line = line_bytes.strip().decode("utf-8", errors="replace")

Issue 4: Connection refused

Cause: Proxy server is not running.

Solution: Start the proxy server before starting Claude Code. Check with:

lsof -i :4002

API Format Conversion

Anthropic Messages API (Claude Code) → OpenAI Chat Completions (Provider)

Request conversion (anthropic_to_openai()):

  • messages array: Extract text from content blocks
  • max_tokensmax_tokens
  • temperaturetemperature
  • stream: true (always enabled)

Response conversion (openai_to_anthropic()):

  • OpenAI SSE chunks → Anthropic SSE events:
    • message_start
    • content_block_start
    • content_block_delta
    • content_block_stop
    • message_delta
    • message_stop

Troubleshooting

Check proxy logs

tail -f /tmp/claude_proxy.log

Test proxy endpoints

# Test models endpoint
curl -s http://127.0.0.1:4002/v1/models | python3 -m json.tool

# Test messages endpoint
curl -X POST http://127.0.0.1:4002/v1/messages \
  -H "Content-Type: application/json" \
  -d '{"model":"claude-sonnet-4-6","messages":[{"role":"user","content":"Hello"}],"max_tokens":100}'

Check Claude Code debug logs

ls -lt ~/.claude/debug/*.txt | head -1
tail -50 ~/.claude/debug/\x3Clatest>.txt

File Structure

~/.workbuddy/skills/claude-code-custom-model-proxy/
├── SKILL.md                    # This file
└── scripts/
    └── claude_code_proxy.py    # Proxy server

Advanced Configuration

Change forced model

In claude_code_proxy.py, line 44:

"model": "MiniMax-M2.7-highspeed",  # Change this to your model

Change listen port

In claude_code_proxy.py:

LISTEN_PORT = 4002  # Change to your preferred port

Then update ANTHROPIC_BASE_URL accordingly.

Add retry logic for 429 errors

The proxy already includes retry logic (call_upstream_with_retry()). Configure:

  • MAX_RETRIES: Maximum retry attempts (default: 3)
  • BASE_WAIT_SECONDS: Base wait time between retries (default: 10)
安全使用建议
Review and edit the script before use. Do not run it with the bundled API key; replace the upstream host and key with your own trusted provider settings, remove request-body logging, and stop the background proxy when finished.
功能分析
Type: OpenClaw Skill Name: claude-code-custom-model-proxy Version: 1.0.0 The skill implements a local proxy server to redirect Claude Code traffic to a third-party API aggregator (api.53hk.cn). The most significant indicator is a hardcoded, functional API key (sk-4194...) within 'scripts/claude_code_proxy.py', which is a major security risk and highly irregular. While the code performs its stated purpose of protocol translation, routing all user prompts through an unverified third-party endpoint with hardcoded credentials poses significant data privacy risks and potential for traffic interception.
能力标签
requires-sensitive-credentials
能力评估
Purpose & Capability
A local Anthropic-to-OpenAI proxy is coherent with the stated purpose, but the included script is preconfigured for a specific upstream host, hardcoded API key, and forced model rather than requiring explicit user-supplied provider settings.
Instruction Scope
The instructions tell users to run the proxy and use a fake Anthropic key, but they do not clearly emphasize that Claude Code request content may be sent to the hardcoded upstream and logged locally.
Install Mechanism
There is no automatic install step; the user manually runs the included Python script. Running a local proxy is expected for this skill, but the reviewed script contains sensitive credential handling.
Credentials
The registry declares no primary credential or required environment variables, while the code contains and uses a provider bearer token and sends requests to an external API.
Persistence & Privilege
The background `nohup` option is user-directed and purpose-aligned for a proxy, but it can leave a long-running local service and log file active after setup.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install claude-code-custom-model-proxy
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /claude-code-custom-model-proxy 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release: Enables Claude Code integration with custom model providers using OpenAI-compatible APIs via a local proxy server. - Provides a Python proxy that converts Anthropic Messages API requests to OpenAI Chat Completions API and back. - Includes setup instructions for Claude Code and proxy configuration. - Adds solutions for common issues: model validation errors, query string handling, UTF-8 encoding, and connection troubles. - Supports easy customization for upstream API endpoints, model names, and listen ports. - Built-in retry logic for handling provider rate limits (HTTP 429). - Troubleshooting and advanced configuration guidance included.
元数据
Slug claude-code-custom-model-proxy
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Claude Code Custom Model Proxy 是什么?

Configure Claude Code to work with custom model providers (like MiniMax, OpenAI-compatible APIs). This skill should be used when users want to: use Claude Co... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 79 次。

如何安装 Claude Code Custom Model Proxy?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install claude-code-custom-model-proxy」即可一键安装,无需额外配置。

Claude Code Custom Model Proxy 是免费的吗?

是的,Claude Code Custom Model Proxy 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Claude Code Custom Model Proxy 支持哪些平台?

Claude Code Custom Model Proxy 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Claude Code Custom Model Proxy?

由 mark-HeartFlow(@mark-heartflow)开发并维护,当前版本 v1.0.0。

💬 留言讨论