跳转到主要内容

开启openclaw http 端点

OpenClaw 的网关可以服务当作一个OpenAI兼容网关,调用其中的agent来提供服务

开启gateway http


  "gateway": {
    "http": {
      "endpoints": {
        "chatCompletions": {
          "enabled": true
        }
      }
    }
  }

可端点


/v1/chat/completions │ POST │ 聊天补全(兼容 OpenAI)
/v1/models           │ GET  │ 列出可用模型(这个在后面需要用到)
/v1/models/{id}      │ GET  │ 获取特定模型信息        
/v1/embeddings       │ POST │ 文本嵌入
/v1/responses        │ POST │ OpenClaw 原生响应 API           

使用

获取模型列表

curl --request GET \
  --url http://127.0.0.1:18789/v1/models \
  --header 'Authorization: Bearer *********************' \
  --header 'Content-Type: application/json' \

记住下面ID "id": "openclaw/fly-go", 后面会用到


{
	"object": "list",
	"data": [
		{
			"id": "openclaw/main",
			"object": "model",
			"created": 0,
			"owned_by": "openclaw",
			"permission": []
		},
		{
			"id": "openclaw/fly-go",
			"object": "model",
			"created": 0,
			"owned_by": "openclaw",
			"permission": []
		}
	]
}

调用聊天补全接口

curl --request POST \
  --url http://127.0.0.1:18789/v1/chat/completions \
  --header 'Authorization: Bearer ****************************' \
  --header 'Content-Type: application/json' \
  --data '{
       "model": "openclaw/main",
       "stream": true,
       "messages": [{"role":"user","content":"你好"}]
     }'