AI 服务/图像生成
异步生成图像
POST
/
api
/
ai
/
image
/
generate
/
async
异步生成图像
curl --request POST \
--url https://aitoearn.cn/api/ai/image/generate/async \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--data '
{
"prompt": "A cute orange cat sitting by a window, soft natural light",
"model": "gpt-image-2"
}
'import requests
url = "https://aitoearn.cn/api/ai/image/generate/async"
payload = {
"prompt": "A cute orange cat sitting by a window, soft natural light",
"model": "gpt-image-2"
}
headers = {
"X-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'A cute orange cat sitting by a window, soft natural light',
model: 'gpt-image-2'
})
};
fetch('https://aitoearn.cn/api/ai/image/generate/async', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://aitoearn.cn/api/ai/image/generate/async"
payload := strings.NewReader("{\n \"prompt\": \"A cute orange cat sitting by a window, soft natural light\",\n \"model\": \"gpt-image-2\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"code": 0,
"message": "请求成功",
"data": {
"logId": "string",
"status": "generating"
}
}授权
需要从 AiToEarn 获取 API Key。点击前往「API Key 获取教程」。
请求体
application/json
图像生成模型名称。先调用「图像生成模型」接口(GET /api/ai/models/image/generation),传入其返回的 data[n].name;各模型支持的尺寸、质量、风格与价格以该接口返回为准。
示例:
"gpt-image-2"
图像质量。可选值随模型而不同,以「图像生成模型」接口返回的 data[n].qualities 为准。
示例:
"low"
图像尺寸。可选值随模型而不同,以「图像生成模型」接口返回的 data[n].sizes 为准;不同尺寸的价格不同,见 data[n].pricing。
示例:
"1024x1024"
图像风格。可选值随模型而不同,以「图像生成模型」接口返回的 data[n].styles 为准;返回为空表示该模型不支持风格参数。
⌘I
异步生成图像
curl --request POST \
--url https://aitoearn.cn/api/ai/image/generate/async \
--header 'Content-Type: application/json' \
--header 'X-Api-Key: <api-key>' \
--data '
{
"prompt": "A cute orange cat sitting by a window, soft natural light",
"model": "gpt-image-2"
}
'import requests
url = "https://aitoearn.cn/api/ai/image/generate/async"
payload = {
"prompt": "A cute orange cat sitting by a window, soft natural light",
"model": "gpt-image-2"
}
headers = {
"X-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'X-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'A cute orange cat sitting by a window, soft natural light',
model: 'gpt-image-2'
})
};
fetch('https://aitoearn.cn/api/ai/image/generate/async', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://aitoearn.cn/api/ai/image/generate/async"
payload := strings.NewReader("{\n \"prompt\": \"A cute orange cat sitting by a window, soft natural light\",\n \"model\": \"gpt-image-2\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"code": 0,
"message": "请求成功",
"data": {
"logId": "string",
"status": "generating"
}
}
