Skip to content

本地模型问题(Ollama 等)

编号格式 #NNNNN 对应 GitHub issue,可直接搜索去重。


Ollama 模型在配置 UI 中无法保存

来源:GitHub #38563(2026-03)

现象:在 Control UI 的配置界面添加 Ollama 本地模型时,保存按钮无响应,或提示字段验证失败。

原因:OpenClaw 的 Zod schema 验证要求 API Key 字段非空(为 Anthropic 等云端提供商设计),Ollama 本地运行不需要 API Key,留空导致验证失败。

解决方法

方案 1(推荐):API Key 字段填入任意占位字符串:

API Key: ollama

方案 2:直接编辑 ~/.openclaw/openclaw.json

json5
{
  providers: {
    ollama: {
      baseUrl: "http://127.0.0.1:11434",
      apiKey: "ollama"
    }
  },
  agents: {
    defaults: {
      model: {
        primary: "ollama/llama3.2"
      }
    }
  }
}

Cron 任务或子 Agent 提示 provider 未配置

来源:GitHub #29886(2026-01)

现象:主 Agent 运行正常,但 Cron 定时任务或通过 sessions_spawn 创建的子 Agent 报错:provider 未配置,无法调用 AI 接口。

原因:Cron 任务和子 Agent 在独立的隔离 session 中运行,不继承主进程的环境变量。通过 $ENV_VAR 引用方式配置的 API Key 在隔离环境中不可见。

解决方法

将 API Key 直接写入配置文件,而非通过环境变量引用:

json5
{
  providers: {
    anthropic: {
      apiKey: "sk-ant-xxxxx"   // 直接写值,而非 "$ANTHROPIC_API_KEY"
    }
  }
}

安全提示:如果 openclaw.json 存储在版本控制中,请将其加入 .gitignore,避免 API Key 泄露。


另见