const API_KEY = 'your api key'; // 替换成你的API KEY
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", "Bearer ${API_KEY}");
const raw = JSON.stringify({
"prompt": "a cat",
"size": "1024x1024",
"model": "text2img", //model 对应EasyAI平台的工作流名称
"n": 2
});
// size,n,prompt会自动转换为EasyAI平台的width and height,batchSize,positive,其他参数保持不变,支持EasyAI平台上的所有参数
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
};
// 将http://127.0.0.1:3001换成你的EasyAI后端服务器地址
fetch("http://127.0.0.1:3001/v1/images/generations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));