图像变体
最后更新:2026-11-14
POSThttps://www.sagelib.com/images/variations
图像变体API,基于一张原始图像,生成多个风格/细节相似但不完全相同的图像版本,适用于图片多版本选择、创意扩展等场景。
接口鉴权方式请参考:API接入与鉴权
请求参数
请求头
| 参数名称 | 描述 |
|---|---|
*Authorization string |
鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN} |
*Content-Type string |
可选值:multipart/form-data multipart/form-data; boundary=${boundary},boundary由请求工具自动生成 |
Body 参数
| 参数名称 | 描述 |
|---|---|
model string |
默认值:Default model configured on the channel 模型名称 |
*image string |
用作变体基础的图像,PNG格式 |
n integer |
默认值:1 可选值:1-4 要生成的图像数 |
response_format string |
默认值:url 可选值:url、b64_json 生成的图像返回的格式(部分模型仅支持特定格式,会忽略该字段) |
size string |
默认值:1024x1024 可选值:512x512 ~ 2048x2048 生成图像的大小(部分模型仅支持特定分辨率) |
请求示例
curl -v 'https://www.sagelib.com/images/variations' \
-H "Authorization: Bearer ***" \
-F "image=@test.png" \
-F "size=1024x1024"
import requests
base_url = "https://www.sagelib.com"
api_key = "***"
url = f"https://www.sagelib.com/images/variations"
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
data = {
"size": "1024x1024"
}
files = {
"image": ("image.bin", open("image.bin", "rb"))
}
response = requests.post(url, headers=headers, data=data, files=files)
print(response.text)
import java.io.*;
import java.net.URI;
import java.net.http.*;
public class LlmStreamClient {
public static void main(String[] args) throws Exception {
String baseUrl = "https://www.sagelib.com";
String apiKey = "***";
String url = "https://www.sagelib.com/images/variations";
String boundary = "----Boundary" + System.currentTimeMillis();
String CRLF = "\r\n";
StringBuilder sb = new StringBuilder();
sb.append("--").append(boundary).append(CRLF);
sb.append("Content-Disposition: form-data; name=\"image\"").append(CRLF).append(CRLF);
sb.append("@test.png").append(CRLF);
sb.append("--").append(boundary).append(CRLF);
sb.append("Content-Disposition: form-data; name=\"size\"").append(CRLF).append(CRLF);
sb.append("1024x1024").append(CRLF);
sb.append("--").append(boundary).append("--").append(CRLF);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
.header("Authorization", "Bearer " + apiKey)
.POST(HttpRequest.BodyPublishers.ofString(sb.toString()))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println("Status Code: " + response.statusCode());
System.out.println(response.body());
}
}
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
)
func main() {
baseUrl := "https://www.sagelib.com"
apiKey := "***"
url := "https://www.sagelib.com/images/variations"
var buf bytes.Buffer
writer := multipart.NewWriter(&buf)
_ = writer.WriteField("image", "@test.png")
_ = writer.WriteField("size", "1024x1024")
writer.Close()
req, err := http.NewRequest("POST", url, &buf)
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", writer.FormDataContentType())
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)
fmt.Println("Status Code:", resp.StatusCode)
fmt.Println(string(body))
}
响应参数
Body 参数
| 参数名称 | 描述 |
|---|---|
created integer |
生成图像的创建时间戳(Unix时间格式) |
data array |
生成图像数组,数组长度与请求参数n一致 |
url string |
生成图像的URL地址,仅当response_format=url时返回(必填) |
b64_json string |
生成图像内容的Base64编码,仅当response_format=b64_json时返回(必填) |
响应示例
{
"created": 1589478378,
"data": [
{
"url": "https://..."
},
{
"url": "https://..."
}
]
}
状态码
| HTTP状态码 | 描述 |
|---|---|
| 200 | 请求成功,返回编辑后的图像数据 |
| 401 | 访问被拒绝,拒绝原因见响应主体。可能原因:缺少Authorization请求头、token无效或过期等 |
| 403 | 访问被拒绝,拒绝原因见响应主体。可能原因:请求主体格式错误、缺少必填参数(如image、prompt)等 |
| 500 | 服务器内部错误,错误原因见响应主体 |