seedream图片接口
curl --request POST \
--url https://api.example.com/v1/images/generations \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"image": {},
"layer_decomposition": true,
"size": "<string>",
"optimize_prompt_options": {
"mode": "<string>"
},
"output_format": "<string>",
"background": "<string>",
"output_compression": 123,
"response_format": "<string>",
"sequential_image_generation": "<string>",
"sequential_image_generation_options": {
"max_images": 123
},
"stream": true,
"watermark": true
}
'import requests
url = "https://api.example.com/v1/images/generations"
payload = {
"model": "<string>",
"prompt": "<string>",
"image": {},
"layer_decomposition": True,
"size": "<string>",
"optimize_prompt_options": { "mode": "<string>" },
"output_format": "<string>",
"background": "<string>",
"output_compression": 123,
"response_format": "<string>",
"sequential_image_generation": "<string>",
"sequential_image_generation_options": { "max_images": 123 },
"stream": True,
"watermark": True
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
prompt: '<string>',
image: {},
layer_decomposition: true,
size: '<string>',
optimize_prompt_options: {mode: '<string>'},
output_format: '<string>',
background: '<string>',
output_compression: 123,
response_format: '<string>',
sequential_image_generation: '<string>',
sequential_image_generation_options: {max_images: 123},
stream: true,
watermark: true
})
};
fetch('https://api.example.com/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.example.com/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>',
'image' => [
],
'layer_decomposition' => true,
'size' => '<string>',
'optimize_prompt_options' => [
'mode' => '<string>'
],
'output_format' => '<string>',
'background' => '<string>',
'output_compression' => 123,
'response_format' => '<string>',
'sequential_image_generation' => '<string>',
'sequential_image_generation_options' => [
'max_images' => 123
],
'stream' => true,
'watermark' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"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.example.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": {},\n \"layer_decomposition\": true,\n \"size\": \"<string>\",\n \"optimize_prompt_options\": {\n \"mode\": \"<string>\"\n },\n \"output_format\": \"<string>\",\n \"background\": \"<string>\",\n \"output_compression\": 123,\n \"response_format\": \"<string>\",\n \"sequential_image_generation\": \"<string>\",\n \"sequential_image_generation_options\": {\n \"max_images\": 123\n },\n \"stream\": true,\n \"watermark\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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.example.com/v1/images/generations")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": {},\n \"layer_decomposition\": true,\n \"size\": \"<string>\",\n \"optimize_prompt_options\": {\n \"mode\": \"<string>\"\n },\n \"output_format\": \"<string>\",\n \"background\": \"<string>\",\n \"output_compression\": 123,\n \"response_format\": \"<string>\",\n \"sequential_image_generation\": \"<string>\",\n \"sequential_image_generation_options\": {\n \"max_images\": 123\n },\n \"stream\": true,\n \"watermark\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": {},\n \"layer_decomposition\": true,\n \"size\": \"<string>\",\n \"optimize_prompt_options\": {\n \"mode\": \"<string>\"\n },\n \"output_format\": \"<string>\",\n \"background\": \"<string>\",\n \"output_compression\": 123,\n \"response_format\": \"<string>\",\n \"sequential_image_generation\": \"<string>\",\n \"sequential_image_generation_options\": {\n \"max_images\": 123\n },\n \"stream\": true,\n \"watermark\": true\n}"
response = http.request(request)
puts response.read_body{
"created": 123,
"model": "<string>",
"data": [
{
"b64_json": "<string>",
"revised_prompt": "<string>",
"output_format": "<string>",
"z_index": 123,
"name": "<string>",
"bounding_box": {
"absolute": [
123
],
"normalized": [
123
]
},
"url": "<string>",
"size": "<string>",
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>",
"param": "<string>"
},
"description": "<string>"
}
],
"usage": {
"output_tokens": 123,
"total_tokens": 123,
"generated_images": 123,
"input_images": 123
}
}图片
Seedream 图片生成接口
兼容 Seedream 官方协议的图片生成接口,支持文生图、图生图、组图与图层分解
POST
/
v1
/
images
/
generations
seedream图片接口
curl --request POST \
--url https://api.example.com/v1/images/generations \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"prompt": "<string>",
"image": {},
"layer_decomposition": true,
"size": "<string>",
"optimize_prompt_options": {
"mode": "<string>"
},
"output_format": "<string>",
"background": "<string>",
"output_compression": 123,
"response_format": "<string>",
"sequential_image_generation": "<string>",
"sequential_image_generation_options": {
"max_images": 123
},
"stream": true,
"watermark": true
}
'import requests
url = "https://api.example.com/v1/images/generations"
payload = {
"model": "<string>",
"prompt": "<string>",
"image": {},
"layer_decomposition": True,
"size": "<string>",
"optimize_prompt_options": { "mode": "<string>" },
"output_format": "<string>",
"background": "<string>",
"output_compression": 123,
"response_format": "<string>",
"sequential_image_generation": "<string>",
"sequential_image_generation_options": { "max_images": 123 },
"stream": True,
"watermark": True
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
prompt: '<string>',
image: {},
layer_decomposition: true,
size: '<string>',
optimize_prompt_options: {mode: '<string>'},
output_format: '<string>',
background: '<string>',
output_compression: 123,
response_format: '<string>',
sequential_image_generation: '<string>',
sequential_image_generation_options: {max_images: 123},
stream: true,
watermark: true
})
};
fetch('https://api.example.com/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.example.com/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>',
'image' => [
],
'layer_decomposition' => true,
'size' => '<string>',
'optimize_prompt_options' => [
'mode' => '<string>'
],
'output_format' => '<string>',
'background' => '<string>',
'output_compression' => 123,
'response_format' => '<string>',
'sequential_image_generation' => '<string>',
'sequential_image_generation_options' => [
'max_images' => 123
],
'stream' => true,
'watermark' => true
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"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.example.com/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": {},\n \"layer_decomposition\": true,\n \"size\": \"<string>\",\n \"optimize_prompt_options\": {\n \"mode\": \"<string>\"\n },\n \"output_format\": \"<string>\",\n \"background\": \"<string>\",\n \"output_compression\": 123,\n \"response_format\": \"<string>\",\n \"sequential_image_generation\": \"<string>\",\n \"sequential_image_generation_options\": {\n \"max_images\": 123\n },\n \"stream\": true,\n \"watermark\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
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.example.com/v1/images/generations")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": {},\n \"layer_decomposition\": true,\n \"size\": \"<string>\",\n \"optimize_prompt_options\": {\n \"mode\": \"<string>\"\n },\n \"output_format\": \"<string>\",\n \"background\": \"<string>\",\n \"output_compression\": 123,\n \"response_format\": \"<string>\",\n \"sequential_image_generation\": \"<string>\",\n \"sequential_image_generation_options\": {\n \"max_images\": 123\n },\n \"stream\": true,\n \"watermark\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/v1/images/generations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"prompt\": \"<string>\",\n \"image\": {},\n \"layer_decomposition\": true,\n \"size\": \"<string>\",\n \"optimize_prompt_options\": {\n \"mode\": \"<string>\"\n },\n \"output_format\": \"<string>\",\n \"background\": \"<string>\",\n \"output_compression\": 123,\n \"response_format\": \"<string>\",\n \"sequential_image_generation\": \"<string>\",\n \"sequential_image_generation_options\": {\n \"max_images\": 123\n },\n \"stream\": true,\n \"watermark\": true\n}"
response = http.request(request)
puts response.read_body{
"created": 123,
"model": "<string>",
"data": [
{
"b64_json": "<string>",
"revised_prompt": "<string>",
"output_format": "<string>",
"z_index": 123,
"name": "<string>",
"bounding_box": {
"absolute": [
123
],
"normalized": [
123
]
},
"url": "<string>",
"size": "<string>",
"error": {
"code": "<string>",
"message": "<string>",
"type": "<string>",
"param": "<string>"
},
"description": "<string>"
}
],
"usage": {
"output_tokens": 123,
"total_tokens": 123,
"generated_images": 123,
"input_images": 123
}
}此接口与 Seedream 官方协议一致,在 OpenAI Images 协议基础上扩展了 Seedream 专属参数,支持参考图输入、组图生成与图层分解等能力。
生成成功后返回图片数据:
功能特性
- 兼容 OpenAI Images 协议基础参数(
prompt、size、output_format等) - 支持图生图,通过
image传入参考图片(URL 或 Base64) - 支持组图生成
sequential_image_generation,基于输入内容生成一组内容关联的图片,可配置最大数量 - 支持图层分解
layer_decomposition,返回拆分后的图层与边界框信息 - 支持提示词优化
optimize_prompt_options(standard/fast两种模式) - 支持
1K、2K等分辨率档位与1024x1024等具体尺寸 - 支持水印控制
watermark
认证方式
在请求头中携带Authorization 字段,格式为 Bearer YOUR_API_KEY。
支持的图片模型
seedream 系列模型。快速示例
import requests
url = "https://api.haitoken.ai/v1/images/generations"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"model": "dola-seedream-5.0-pro",
"prompt": "一只橘猫戴着宇航员头盔漂浮在太空中,背景是地球",
"size": "2K",
"watermark": False,
"response_format": "url"
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
const response = await fetch('https://api.haitoken.ai/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'dola-seedream-5.0-pro',
prompt: '一只橘猫戴着宇航员头盔漂浮在太空中,背景是地球',
size: '2K',
watermark: false,
response_format: 'url'
})
});
const data = await response.json();
console.log(data);
curl -X POST 'https://api.haitoken.ai/v1/images/generations' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"model": "dola-seedream-5.0-pro",
"prompt": "一只橘猫戴着宇航员头盔漂浮在太空中,背景是地球",
"size": "2K",
"watermark": false,
"response_format": "url"
}'
{
"created": 1787875200,
"model": "dola-seedream-5.0-pro",
"data": [
{
"url": "https://example.com/images/generated-1.png",
"size": "2048x2048"
}
],
"usage": {
"output_tokens": 8320,
"total_tokens": 8320,
"generated_images": 1,
"input_images": 0
}
}
下一步
- 查看 OpenAI 图片生成接口 了解基础协议参数
- 查看 OpenAI 图片编辑接口 编辑已有图片
- 查看 模型列表 了解可用的图片模型
请求体
application/json
模型名称
提示词
参考图片,URL 或 Base64 字符串(Seedream 扩展参数,用于图生图)
是否进行图层分解: true 分解,false 不分解(default)
生成图片尺寸,如 "1024x1024"、"1K“、“2K”等
提示词优化选项
Show child attributes
Show child attributes
输出图片格式,如 "png"、"jpeg"、"webp"
设置生成图像的背景: "transparent" /"opaque"/ "auto" 默认为 "auto"
输出压缩率
响应格式,"url" 或 "b64_json"
控制是否关闭组图功能(组图:基于您输入的内容,生成的一组内容关联的图片)。"auto"/"disabled" 默认为 "disabled"
组图功能的配置。仅当 sequential_image_generation 为 auto 时生效。
Show child attributes
Show child attributes
是否使用流式响应(SSE)
是否添加水印