文生图
curl --request POST \
--url https://api.chenyu.cn/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"size": "<string>",
"n": 123,
"response_format": "<string>",
"reference_image": "<string>",
"reference_images": [
{}
]
}
'import requests
url = "https://api.chenyu.cn/v1/images/generations"
payload = {
"model": "<string>",
"prompt": "<string>",
"size": "<string>",
"n": 123,
"response_format": "<string>",
"reference_image": "<string>",
"reference_images": [{}]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
prompt: '<string>',
size: '<string>',
n: 123,
response_format: '<string>',
reference_image: '<string>',
reference_images: [{}]
})
};
fetch('https://api.chenyu.cn/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.chenyu.cn/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'prompt' => '<string>',
'size' => '<string>',
'n' => 123,
'response_format' => '<string>',
'reference_image' => '<string>',
'reference_images' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.chenyu.cn/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"n\": 123,\n \"response_format\": \"<string>\",\n \"reference_image\": \"<string>\",\n \"reference_images\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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))
}HttpResponse<String> response = Unirest.post("https://api.chenyu.cn/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"n\": 123,\n \"response_format\": \"<string>\",\n \"reference_image\": \"<string>\",\n \"reference_images\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.chenyu.cn/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"n\": 123,\n \"response_format\": \"<string>\",\n \"reference_image\": \"<string>\",\n \"reference_images\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"created": 123,
"data": [
{
"url": "<string>"
}
]
}直接 API 调用
文生图
使用文本提示词生成图片
POST
/
v1
/
images
/
generations
文生图
curl --request POST \
--url https://api.chenyu.cn/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"size": "<string>",
"n": 123,
"response_format": "<string>",
"reference_image": "<string>",
"reference_images": [
{}
]
}
'import requests
url = "https://api.chenyu.cn/v1/images/generations"
payload = {
"model": "<string>",
"prompt": "<string>",
"size": "<string>",
"n": 123,
"response_format": "<string>",
"reference_image": "<string>",
"reference_images": [{}]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
prompt: '<string>',
size: '<string>',
n: 123,
response_format: '<string>',
reference_image: '<string>',
reference_images: [{}]
})
};
fetch('https://api.chenyu.cn/v1/images/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.chenyu.cn/v1/images/generations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'prompt' => '<string>',
'size' => '<string>',
'n' => 123,
'response_format' => '<string>',
'reference_image' => '<string>',
'reference_images' => [
[
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.chenyu.cn/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"n\": 123,\n \"response_format\": \"<string>\",\n \"reference_image\": \"<string>\",\n \"reference_images\": [\n {}\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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))
}HttpResponse<String> response = Unirest.post("https://api.chenyu.cn/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"n\": 123,\n \"response_format\": \"<string>\",\n \"reference_image\": \"<string>\",\n \"reference_images\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.chenyu.cn/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"size\": \"<string>\",\n \"n\": 123,\n \"response_format\": \"<string>\",\n \"reference_image\": \"<string>\",\n \"reference_images\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"created": 123,
"data": [
{
"url": "<string>"
}
]
}文生图
使用 OpenAI Images 兼容格式生成图片。支持在
reference_image、reference_images、image、images、input_image、input_image_url、mask 等字段中传入图片资源。图片资源可以是公网 URL、data:image/<format>;base64,<data> 或 asset://asset_xxx;需要在提示词中引用素材时,使用 { "uri": "...", "label": "参考图" },详见 上传资源。请求参数
图片生成模型 ID
图片生成提示词
图片尺寸,例如
1024x1024、2k、3k。网关会自动适配上游模型的尺寸要求生成图片数量
返回格式,通常为
url参考图片。直接传资源字符串:公网 URL、data URL 或
asset://asset_xxx。需要在 prompt 中引用时,可传 { "uri": "...", "label": "参考图" }多张参考图片。数组元素支持与
reference_image 相同的写法;每个对象可以设置不同 label响应参数
创建时间戳
代码示例
import requests
url = "https://api.chenyu.cn/v1/images/generations"
headers = {
"Authorization": "Bearer your_api_key",
"Content-Type": "application/json"
}
payload = {
"model": "doubao-seedream-5-0-lite-260128",
"prompt": "电商主图,白底,一瓶护肤品,柔和布光",
"size": "1024x1024",
"reference_image": "asset://asset_reference_image"
}
response = requests.post(url, headers=headers, json=payload)
print(response.json()["data"][0]["url"])
const axios = require('axios');
axios.post('https://api.chenyu.cn/v1/images/generations', {
model: 'doubao-seedream-5-0-lite-260128',
prompt: '电商主图,白底,一瓶护肤品,柔和布光',
size: '1024x1024',
reference_image: 'asset://asset_reference_image'
}, {
headers: {
Authorization: 'Bearer your_api_key',
'Content-Type': 'application/json'
}
}).then((response) => {
console.log(response.data.data[0].url);
});
curl -X POST "https://api.chenyu.cn/v1/images/generations" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seedream-5-0-lite-260128",
"prompt": "电商主图,白底,一瓶护肤品,柔和布光",
"size": "1024x1024",
"reference_image": "asset://asset_reference_image"
}'
响应示例
{
"created": 1780000000,
"data": [
{
"url": "https://example.com/generated.png"
}
]
}
提示词引用素材
在参考图对象中传label 后,可以在 prompt 里用 @label 指向该图片。label 不需要带 @,同一请求内不能重复。
{
"model": "doubao-seedream-5-0-lite-260128",
"prompt": "参考 @产品图 的主体结构,生成一张白底电商主图",
"size": "1024x1024",
"reference_image": {
"uri": "asset://asset_product_reference",
"label": "产品图"
}
}
⌘I