OpenClaw配置千问Qwen免费大模型教程

AI大语言模型

虽然OpenClaw支持的大模型非常多,但大多数免费API配额限制都比较严格。千问Qwen免费配额为每天2000次调用,对于普通用户基本够用。要想管够又省钱,可以考虑主模型Qwen,备用模型硅基流动(OpenClaw配置硅基流动大模型方法)。

OpenClaw配置千问Qwen大模型

执行OpenClaw模型配置命令:

openclaw configure --section model

选择OpenClaw网关:

选择OpenClaw网关

选择Qwen模型:

选择Qwen模型

复制授权URL到浏览器打开:

OpenClaw千问Qwen授权URL

根据页面提示注册/登录千问账号(免费):

授权千问Qwen给OpenClaw

授权成功后,OpenClaw会自动进入下一步:选择模型。默认已选择了Qwen模型:

选择Qwen大模型

配置文件说明

主配置文件openclaw.json内容如下:

"auth": {
    "profiles": {
        "qwen-portal:default": {
            "provider": "qwen-portal",
            "mode": "oauth"
        }
    }
},
"models": {
    "providers": {
        "qwen-portal": {
            "baseUrl": "https://portal.qwen.ai/v1",
            "apiKey": "qwen-oauth",
            "api": "openai-completions",
            "models": [
                {
                    "id": "coder-model",
                    "name": "Qwen Coder",
                    "reasoning": false,
                    "input": [
                        "text"
                    ],
                    "cost": {
                        "input": 0,
                        "output": 0,
                        "cacheRead": 0,
                        "cacheWrite": 0
                    },
                    "contextWindow": 128000,
                    "maxTokens": 8192
                },
                {
                    "id": "vision-model",
                    "name": "Qwen Vision",
                    "reasoning": false,
                    "input": [
                        "text",
                        "image"
                    ],
                    "cost": {
                        "input": 0,
                        "output": 0,
                        "cacheRead": 0,
                        "cacheWrite": 0
                    },
                    "contextWindow": 128000,
                    "maxTokens": 8192
                }
            ]
        }
    }
},
"agents": {
    "defaults": {
        "model": {
            "primary": "qwen-portal/coder-model",
            "fallbacks": [
                "qwen-portal/vision-model"
            ]
        },
        "models": {
            "qwen-portal/coder-model": {
                "alias": "qwen-code"
            },
            "qwen-portal/vision-model": {
                "alias": "qwen"
            }
        }
    }
},
"plugins": {
    "entries": {
        "qwen-portal-auth": {
            "enabled": true
        }
    }
}

其他配置信息位于以下路径:

~/.openclaw/agents/main/agent/

models.json内容如下:

{
  "providers": {
    "qwen-portal": {
      "baseUrl": "https://portal.qwen.ai/v1",
      "api": "openai-completions",
      "models": [
        {
          "id": "coder-model",
          "name": "Qwen Coder",
          "reasoning": false,
          "input": [
            "text"
          ],
          "cost": {
            "input": 0,
            "output": 0,
            "cacheRead": 0,
            "cacheWrite": 0
          },
          "contextWindow": 128000,
          "maxTokens": 8192
        },
        {
          "id": "vision-model",
          "name": "Qwen Vision",
          "reasoning": false,
          "input": [
            "text",
            "image"
          ],
          "cost": {
            "input": 0,
            "output": 0,
            "cacheRead": 0,
            "cacheWrite": 0
          },
          "contextWindow": 128000,
          "maxTokens": 8192
        }
      ],
      "apiKey": "qwen-oauth"
    }
  }
}

auth-profiles.json内容如下:

{
  "version": 1,
  "profiles": {
    "qwen-portal:default": {
      "type": "oauth",
      "provider": "qwen-portal",
      "access": "",
      "refresh": "",
      "expires": 0
    }
  },
  "lastGood": {
    "qwen-portal": "qwen-portal:default"
  },
  "usageStats": {
    "qwen-portal:default": {
      "lastUsed": 0,
      "errorCount": 0,
      "lastFailureAt": 0
    }
  }
}

auth.json内容如下:

{
  "qwen-portal": {
    "type": "oauth",
    "access": "",
    "refresh": "",
    "expires": 0
  }
}

别忘了重启一下OpenClaw网关:

openclaw gateway restart

会话窗口查看当前使用的模型:

/status
AI大语言模型