doubao-seedream-4-5-251128
最后更新:2026-11-14
POSThttps://www.sagelib.com/images/generations
doubao-seedream-4-5-251128 模型的图像生成接口,OpenAI兼容,支持文生图、图像参数配置等。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
默认值:application/json 可选值:application/json 内容类型,固定为 application/json |
Body 参数
| 参数名称 | 描述 |
|---|---|
*model string |
可选值:Model identifier 指定使用的模型,固定为 doubao-seedream-4-5-251128 |
*prompt string |
可选值:Text prompt 图像生成提示词,描述期望生成的图像内容 |
image array |
可选值:List of reference image URLs 图生图/多图融合参考图,支持 1-3 张 |
response_format string |
默认值:url 可选值:url、b64_json 响应返回载体格式:url=图片链接,b64_json=base64 编码 |
size string |
默认值:2K 可选值:2K 输出分辨率预设档位 |
seed integer |
可选值:Any integer 随机种子,控制生成随机性,提高可复现性 |
guidance_scale float |
默认值:5.5 可选值:Recommended 3.0-7.0 提示词遵循度,控制 prompt 对生成的影响强度 |
watermark boolean |
可选值:true、false 是否添加 AI 生成水印 |
optimize_prompt boolean |
可选值:true、false 是否启用 prompt 自动优化 |
optimize_prompt_options object |
可选值:mode prompt 优化选项,子字段 thinking(enabled)、mode |
sequential_image_generation string |
默认值:auto 可选值:auto、disabled 多图生成模式:auto=自动判定返回多图,disabled=仅生成单图 |
sequential_image_generation_options object |
可选值:Sub-field max_images 多图选项,子字段 max_images 指定最大生成图片数量 |
stream boolean |
默认值:false 可选值:true、false 是否流式输出(SSE) |
请求示例
curl -v 'https://www.sagelib.com/images/generations' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"stream": false,
"size": "2K"
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/images/generations"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "doubao-seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"stream": False,
"size": "2K"
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class LlmStreamClient {
public static void main(String[] args) {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/images/generations";
String jsonRequestBody = """
{
"model": "doubao-seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"stream": false,
"size": "2K"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
.build();
try {
// Use ofInputStream to handle the streaming response
HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("data:")) {
String data = line.substring(5).trim();
if ("[DONE]".equals(data)) {
break;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
System.out.println("Received stream chunk: " + data);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/images/generations"
jsonRequestBody := `
{
"model": "doubao-seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"stream": false,
"size": "2K"
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
// Pretty-print the returned JSON data
var prettyBody map[string]interface{}
if err := json.Unmarshal(body, &prettyBody); err == nil {
pretty, _ := json.MarshalIndent(prettyBody, "", " ")
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(pretty))
} else {
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
}
curl -v 'https://www.sagelib.com/images/generations' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seedream-4-5-251128",
"prompt": "A cat on the grass",
"size": "2k",
"watermark": true
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/images/generations"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "doubao-seedream-4-5-251128",
"prompt": "A cat on the grass",
"size": "2k",
"watermark": True
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class LlmStreamClient {
public static void main(String[] args) {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/images/generations";
String jsonRequestBody = """
{
"model": "doubao-seedream-4-5-251128",
"prompt": "A cat on the grass",
"size": "2k",
"watermark": true
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
.build();
try {
// Use ofInputStream to handle the streaming response
HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("data:")) {
String data = line.substring(5).trim();
if ("[DONE]".equals(data)) {
break;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
System.out.println("Received stream chunk: " + data);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/images/generations"
jsonRequestBody := `
{
"model": "doubao-seedream-4-5-251128",
"prompt": "A cat on the grass",
"size": "2k",
"watermark": true
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
// Pretty-print the returned JSON data
var prettyBody map[string]interface{}
if err := json.Unmarshal(body, &prettyBody); err == nil {
pretty, _ := json.MarshalIndent(prettyBody, "", " ")
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(pretty))
} else {
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
}
curl -v 'https://www.sagelib.com/images/generations' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seedream-4-5-251128",
"prompt": "A cat",
"sequential_image_generation": "auto",
"sequential_image_generation_options": {},
"size": "2k"
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/images/generations"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "doubao-seedream-4-5-251128",
"prompt": "A cat",
"sequential_image_generation": "auto",
"sequential_image_generation_options": {},
"size": "2k"
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class LlmStreamClient {
public static void main(String[] args) {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/images/generations";
String jsonRequestBody = """
{
"model": "doubao-seedream-4-5-251128",
"prompt": "A cat",
"sequential_image_generation": "auto",
"sequential_image_generation_options": {},
"size": "2k"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
.build();
try {
// Use ofInputStream to handle the streaming response
HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("data:")) {
String data = line.substring(5).trim();
if ("[DONE]".equals(data)) {
break;
}
// Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
System.out.println("Received stream chunk: " + data);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/images/generations"
jsonRequestBody := `
{
"model": "doubao-seedream-4-5-251128",
"prompt": "A cat",
"sequential_image_generation": "auto",
"sequential_image_generation_options": {},
"size": "2k"
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
// Pretty-print the returned JSON data
var prettyBody map[string]interface{}
if err := json.Unmarshal(body, &prettyBody); err == nil {
pretty, _ := json.MarshalIndent(prettyBody, "", " ")
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(pretty))
} else {
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
}
响应参数
Body 参数
| 参数名称 | 描述 |
|---|---|
created integer |
生成时间戳(Unix 秒) |
model string |
模型名称 |
data array |
图片结果数组 |
data[0] object |
|
url string |
生成图片的访问链接(response_format=url 时返回) |
b64_json string |
生成图片的 base64 编码(response_format=b64_json 时返回) |
usage object |
token 用量统计 |
input_tokens integer |
输入 token 数 |
output_tokens integer |
输出 token 数 |
total_tokens integer |
总 token 数 |
POSThttps://www.sagelib.com/openai/images/generations
doubao-seedream-4-5-251128 模型的图像生成接口,OpenAI直连模式(URL 前缀 /openai),支持 2K/4K 分辨率、流式输出、组图生成等。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
可选值:application/json application/json |
Body 参数
| 参数名称 | 描述 |
|---|---|
*model string |
可选值:seedream-4-5-251128 指定使用的模型,固定值 |
*prompt string |
可选值:Text prompt 图像生成提示词,描述期望生成的图像内容 |
image string |
可选值:List of reference image URLs 图生图/多图融合参考图,支持 1-3 张 |
response_format string |
默认值:url 可选值:url / b64_json 响应返回载体格式:url=图片链接,b64_json=base64 编码 |
size string |
默认值:2K 可选值:2K / 4K 输出分辨率预设档位(无 3K 档) |
seed integer |
可选值:Any integer 随机种子,控制生成随机性 |
guidance_scale number |
默认值:5.5 可选值:Recommended 3.0-7.0 提示词遵循度 |
watermark boolean |
可选值:true、false 是否添加 AI 生成水印 |
optimize_prompt boolean |
可选值:true、false 是否启用 prompt 自动优化 |
optimize_prompt_options object |
可选值:Sub-fields thinking / mode prompt 优化选项 |
sequential_image_generation string |
默认值:auto 可选值:auto / disabled 多图生成模式:auto=自动判定返回多图,disabled=仅生成单图 |
sequential_image_generation_options object |
可选值:Sub-field max_images 多图选项,子字段 max_images 指定最大生成图片数量 |
n integer |
默认值:1 可选值:Positive integer 生成图片数量(OpenAI 直连专属参数) |
stream boolean |
默认值:false 可选值:true、false 是否流式输出(SSE) |
请求示例
curl -v 'https://www.sagelib.com/openai/images/generations' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-4-5-251128",
"prompt": "An egret flies low over a misty lake in the morning, with a clear reflection, ink-wash painting mood, elegant tones, negative space, serene atmosphere",
"size": "2K"
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/openai/images/generations"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "seedream-4-5-251128",
"prompt": "An egret flies low over a misty lake in the morning, with a clear reflection, ink-wash painting mood, elegant tones, negative space, serene atmosphere",
"size": "2K"
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class LlmStreamClient {
public static void main(String[] args) {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/openai/images/generations";
String jsonRequestBody = """
{
"model": "seedream-4-5-251128",
"prompt": "An egret flies low over a misty lake in the morning, with a clear reflection, ink-wash painting mood, elegant tones, negative space, serene atmosphere",
"size": "2K"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
.build();
try {
HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("data:")) {
String data = line.substring(5).trim();
if ("[DONE]".equals(data)) break;
System.out.println("Received stream chunk: " + data);
}
}
}
} catch (Exception e) { e.printStackTrace(); }
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/openai/images/generations"
jsonRequestBody := `
{
"model": "seedream-4-5-251128",
"prompt": "An egret flies low over a misty lake in the morning, with a clear reflection, ink-wash painting mood, elegant tones, negative space, serene atmosphere",
"size": "2K"
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil { fmt.Println("Failed to create request:", err); return }
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil { fmt.Println("Request failed:", err); return }
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
var prettyBody map[string]interface{}
if err := json.Unmarshal(body, &prettyBody); err == nil {
pretty, _ := json.MarshalIndent(prettyBody, "", " ")
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(pretty))
} else {
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
}
curl -v 'https://www.sagelib.com/openai/images/generations' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"stream": true,
"size": "2K"
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/openai/images/generations"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"stream": True,
"size": "2K"
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class LlmStreamClient {
public static void main(String[] args) {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/openai/images/generations";
String jsonRequestBody = """
{
"model": "seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"stream": true,
"size": "2K"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
.build();
try {
HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("data:")) {
String data = line.substring(5).trim();
if ("[DONE]".equals(data)) break;
System.out.println("Received stream chunk: " + data);
}
}
}
} catch (Exception e) { e.printStackTrace(); }
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/openai/images/generations"
jsonRequestBody := `
{
"model": "seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"stream": true,
"size": "2K"
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil { fmt.Println("Failed to create request:", err); return }
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil { fmt.Println("Request failed:", err); return }
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
var prettyBody map[string]interface{}
if err := json.Unmarshal(body, &prettyBody); err == nil {
pretty, _ := json.MarshalIndent(prettyBody, "", " ")
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(pretty))
} else {
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
}
curl -v 'https://www.sagelib.com/openai/images/generations' \
-H "Authorization: Bearer ***" \
-H "Content-Type: application/json" \
-d '{
"model": "seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"seed": 42,
"size": "2K"
}'
import json
import requests
# Configure base variables
base_url = "https://www.sagelib.com" # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***" # Replace with your Bearer token
url = f"https://www.sagelib.com/openai/images/generations"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
data = {
"model": "seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"seed": 42,
"size": "2K"
}
# Send the POST request
response = requests.post(url, headers=headers, json=data)
# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class LlmStreamClient {
public static void main(String[] args) {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/openai/images/generations";
String jsonRequestBody = """
{
"model": "seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"seed": 42,
"size": "2K"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Authorization", "Bearer " + apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
.build();
try {
HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (line.startsWith("data:")) {
String data = line.substring(5).trim();
if ("[DONE]".equals(data)) break;
System.out.println("Received stream chunk: " + data);
}
}
}
} catch (Exception e) { e.printStackTrace(); }
}
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/openai/images/generations"
jsonRequestBody := `
{
"model": "seedream-4-5-251128",
"prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
"seed": 42,
"size": "2K"
}
`
req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
if err != nil { fmt.Println("Failed to create request:", err); return }
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil { fmt.Println("Request failed:", err); return }
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
var prettyBody map[string]interface{}
if err := json.Unmarshal(body, &prettyBody); err == nil {
pretty, _ := json.MarshalIndent(prettyBody, "", " ")
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(pretty))
} else {
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
}
响应参数
Body 参数
| 参数名称 | 描述 |
|---|---|
created integer |
生成时间戳(Unix 秒) |
model string |
模型名称 |
data array |
图片结果数组 |
url string |
生成图片的访问链接(response_format=url 时返回) |
b64_json string |
生成图片的 base64 编码(response_format=b64_json 时返回) |
size string |
生成图片实际分辨率(如 2304x1728) |
usage object |
token 用量统计 |
generated_images integer |
生成图片数 |
output_tokens integer |
输出 token 数 |
total_tokens integer |
总 token 数 |