vLLM 通过 OpenAI 兼容 HTTP API 提供开源模型服务,OpenClaw 支持自动模型发现和流式用量统计。

属性值
Provider IDvllm
认证VLLM_API_KEY(无认证服务器填任意非空值)
APIOpenAI 兼容(openai-completions)
默认 Base URLhttp://127.0.0.1:8000/v1

快速开始

export VLLM_API_KEY="vllm-local"
{
  agents: {
    defaults: {
      model: { primary: "vllm/your-model-id" },
    },
  },
}

模型自动发现

设置 VLLM_API_KEY 且未显式配置 models.providers.vllm 时,OpenClaw 自动查询 GET http://127.0.0.1:8000/v1/models。

使用通配符保持动态发现:

{
  agents: {
    defaults: {
      models: { "vllm/*": {} },
    },
  },
}

显式配置

{
  models: {
    providers: {
      vllm: {
        baseUrl: "http://127.0.0.1:8000/v1",
        apiKey: "${VLLM_API_KEY}",
        api: "openai-completions",
        request: { allowPrivateNetwork: true },
        timeoutSeconds: 300,
        models: [
          {
            id: "your-model-id",
            name: "Local vLLM Model",
            reasoning: false,
            input: ["text"],
            cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
            contextWindow: 128000,
            maxTokens: 8192,
          },
        ],
      },
    },
  },
}

Qwen 模型特殊配置

Qwen 模型通过 vLLM 服务时,thinking 控制需设置 params.qwenThinkingFormat:

  • "chat-template":发送 chat_template_kwargs.enable_thinking
  • "top-level":发送顶层 enable_thinking 标志

若 Qwen 工具调用以文本形式输出,可尝试:

{
  agents: {
    defaults: {
      models: {
        "vllm/Qwen-Qwen2.5-Coder-32B-Instruct": {
          params: { extra_body: { tool_choice: "required" } },
        },
      },
    },
  },
}

故障排查

  • 私有网络访问需设置 request.allowPrivateNetwork: true
  • 慢速模型建议设置 timeoutSeconds: 300
  • 工具调用渲染为文本:检查 vLLM 启动时的 tool-call parser 和 chat template

相关链接