Builder Daily

2026-04-30

LiteLLM + Claude Code 搭配 DGX Spark — LAN 服务配置与协议转换

通过 LiteLLM 代理将 Claude Code API 调用路由到 DGX Spark 上的自建 Qwen3 模型。涵盖配置、模型别名映射、多 GPU 卸载,以及延迟与云端 API 的权衡分析。

Claude Code 向 Anthropic API 格式发送请求。DGX Spark 运行带有 OpenAI 兼容端点的 vLLM。LiteLLM 桥接两者 — 它实时将 Anthropic API 调用转换为 OpenAI API 调用,让 Claude Code 将本地 Qwen3 模型视为 Claude 模型。

架构

Claude Code(Anthropic API)

LiteLLM 代理(localhost:4000)
  • 将 claude-* 别名映射至 Qwen3 模型 ID
  • 转换消息格式 + tool-use 结构

vLLM(http://192.168.68.155:8888/v1)
  • 在 GB10 上提供 Qwen3.6-35B-A3B-NVFP4 服务

LiteLLM 配置

# litellm_config.yaml
model_list:
  - model_name: claude-sonnet-4-20250514
    litellm_params:
      model: openai/Intel/Qwen3.6-35B-A3B-int4-AutoRound
      api_base: http://192.168.68.155:8888/v1
      api_key: none

  - model_name: claude-3-5-sonnet-20241022
    litellm_params:
      model: openai/Intel/Qwen3.6-35B-A3B-int4-AutoRound
      api_base: http://192.168.68.155:8888/v1
      api_key: none

  - model_name: claude-3-opus-20240229
    litellm_params:
      model: openai/Intel/Qwen3.5-27B-int4-AutoRound
      api_base: http://192.168.68.155:8888/v1
      api_key: none

litellm_settings:
  drop_params: true
  set_verbose: false

启动代理:

litellm --config litellm_config.yaml --port 4000

Claude Code 配置

在 Claude Code 设置中配置:

{
  "apiBaseUrl": "http://localhost:4000",
  "apiKey": "sk-local-any-string-works"
}

或使用 shell 启动器模式:

#!/usr/bin/env bash
# claude_local.sh
export ANTHROPIC_API_KEY="sk-local-any-string"
export ANTHROPIC_BASE_URL="http://localhost:4000"
claude "$@"

vLLM 上的 NVFP4 模型

在 GB10 上提供 Qwen3.6-35B-A3B-NVFP4 以获得最佳吞吐量:

docker run -d --gpus all --ipc host --shm-size 64gb \
  -p 8888:8000 \
  -v ~/.cache/huggingface:/root/.cache/huggingface \
  vllm/vllm-openai:cu130-nightly \
  RedHatAI/Qwen3.6-35B-A3B-NVFP4 \
  --served-model-name Intel/Qwen3.6-35B-A3B-int4-AutoRound \
  --host 0.0.0.0 --port 8000 \
  --dtype bfloat16 --gpu-memory-utilization 0.9 \
  --max-model-len 131072 \
  --enable-auto-tool-choice \
  --tool-call-parser qwen3_coder \
  --reasoning-parser qwen3 \
  --moe-backend=flashinfer_cutlass

延迟实际对比

场景延迟
Claude Sonnet 4(云端)0.8–2s TTFT
Qwen3.6-35B NVFP4+MTP(本地)0.15–0.4s TTFT
Qwen3.6-35B NVFP4(无 MTP)0.25–0.6s TTFT
Qwen3.5-27B int4(本地)0.1–0.25s TTFT

在同一 LAN 上,本地 TTFT 低于云端 — 无 TLS 握手,无地理路由。权衡是生成质量:Qwen3.6-35B NVFP4 在代码任务上与 Sonnet 3.5 相当,但在需要 Opus 级别能力的复杂推理上表现不足。

已知问题


Sources

请喝咖啡