MaaS image-1接口文档
请求协议
Http
生成图片:
Header
参数名 | 值 |
---|---|
Authorization | Bearer {YOUR AK} |
Content-Type | application/json |
请求url
https://genaiapi.cloudsway.net/v1/ai/{YOUR ENDPOINT}/images/generations
请求Body:
参数名 | 类型 | 描述 |
---|---|---|
prompt | string | 所需图像的文本描述。最大长度为 32000 个字符。 |
background | string | 允许设置生成图像背景的透明度。必须为 transparent 、opaque 或 auto (默认值)之一。使用 auto 时,模型将自动确定图像的最佳背景。如果为“transparent”,则输出格式需要支持透明度,因此应将其设置为“png”(默认值)或“webp”。 |
model | string | 模型名称 |
moderation | string | 控制生成的图片的内容审核级别。必须为 low (用于限制较少的过滤)或 auto (默认值)。 |
n | int | 要生成的图像数量。必须介于 1 到 10 之间。 |
output_compression | int | 生成图像的压缩级别 (0-100%)。此参数仅适用于输出格式为 webp 或 jpeg ,默认为 100。 |
output_format | string | 返回生成图像的格式。必须是 png 、jpeg 或 webp 之一。 |
quality | string | 生成的图像质量。 - auto (默认值)将自动为给定模型选择最佳质量。 - 支持 high 、medium 和 low 。 |
size | string | 生成的图像的大小。必须是“1024x1024”、“1536x1024”` (横向)、“1024x1536”(纵向)或“自动”(默认值)中的一个 |
user | string | 一个代表最终用户的唯一标识符 |
请求示例
curl --location 'https://genaiapi.cloudsway.net/v1/ai/{YOUR ENDPOINT}/images/generations' \
--header 'Authorization: Bearer {YOUR AK}' \
--header 'Content-Type: application/json' \
--data '{
"prompt": "A photograph of a black fox in an autumn forest",
"size": "1024x1024",
"quality": "medium",
"output_compression": 100,
"output_format": "png",
"n": 1
}
'
响应结果:
参数名 | 类型 | 描述 |
---|---|---|
created | int | 创建图片时的Unix时间戳(秒)。 |
data | List[Image] | 生成的图片列表 |
usage | Usage | 图像生成的令牌使用信息。 |
Image:
参数名 | 类型 | 描述 |
---|---|---|
b64_json | string | 生成图像的base64编码JSON。 |
Usage:
参数名 | 类型 | 描述 |
---|---|---|
input_tokens | int | 输入prompt的令牌数量(图片或者文字) |
input_tokens_details | UsageInputTokensDetails | 图像生成的输入令牌详情 |
output_tokens | int | 输出图片令牌数量 |
total_tokens | int | 图片生成的总的令牌数量 |
UsageInputTokensDetails:
参数名 | 类型 | 描述 |
---|---|---|
image_tokens | int | 输入图片令牌数量 |
text_tokens | int | 输入文本令牌数量 |
示例
{
"created": 1747972711,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEU..."
}
],
"usage": {
"input_tokens": 252,
"output_tokens": 4160,
"total_tokens": 4412,
"input_tokens_details": {
"image_tokens": 194,
"text_tokens": 58
}
}
}
编辑图片:
Header
参数名 | 值 |
---|---|
Authorization | Bearer {YOUR AK} |
Content-Type | multipart/form-data |
请求url
https://genaiapi.cloudsway.net/v1/ai/{YOUR ENDPOINT}/images/edits
请求Body:
参数名 | 类型 | 描述 |
---|---|---|
image | File | 要编辑的图像。必须是受支持的映像文件或映像数组。 每张图片应为小于25MB的 'png'、'webp' 或 'jpg' 的文件,您最多可以提供 16 张图像。 |
prompt | string | 所需图像的文本描述。最大长度为 32000 个字符 |
background | string | 允许设置生成图像背景的透明度。必须为 transparent 、opaque 或 auto (默认值)之一。使用 auto 时,模型将自动确定图像的最佳背景。如果为“transparent”,则输出格式需要支持透明度,因此应将其设置为“png”(默认值)或“webp”。 |
mask | File | 其完全透明区域(例如 alpha 为零)的附加图像 - 指示应该编辑 'image' 的位置。如果提供了多张图片,蒙版将应用于第一张图像。必须是有效的 PNG 文件,小于4MB,并且与 'image' 具有相同的尺寸。 |
model | string | 模型名称 |
n | int | 要生成的图像数量。必须介于 1 到 10 之间。 |
quality | string | 生成的图像质量。 - auto (默认值)将自动为给定模型选择最佳质量。 - 支持 high 、medium 和 low 。 |
size | string | 生成的图像的大小。必须是“1024x1024”、“1536x1024”` (横向)、“1024x1536”(纵向)或“自动”(默认值)中的一个 |
user | string | 一个代表最终用户的唯一标识符 |
请求示例
curl --location 'https://genaiapi.cloudsway.net/v1/ai/{YOUR ENDPOINT}/images/edits' \
--header 'Authorization: Bearer {YOUR AK}' \
--header 'Content-Type: multipart/form-data' \
--form 'image=@"/C:/Desktop/fox.png"' \
--form 'prompt="generate a mask delimiting the entire character in the picture, using white where the character is and black for the background. Return an image in the same size as the input image."'
返回结果
参数名 | 类型 | 描述 |
---|---|---|
created | int | 创建图片时的Unix时间戳(秒)。 |
data | List[Image] | 生成的图片列表 |
usage | Usage | 图像生成的令牌使用信息。 |
Image:
参数名 | 类型 | 描述 |
---|---|---|
b64_json | string | 生成图像的base64编码JSON。 |
Usage:
参数名 | 类型 | 描述 |
---|---|---|
input_tokens | int | 输入prompt的令牌数量(图片或者文字) |
input_tokens_details | UsageInputTokensDetails | 图像生成的输入令牌详情 |
output_tokens | int | 输出图片令牌数量 |
total_tokens | int | 图片生成的总的令牌数量 |
UsageInputTokensDetails:
参数名 | 类型 | 描述 |
---|---|---|
image_tokens | int | 输入图片令牌数量 |
text_tokens | int | 输入文本令牌数量 |
示例
{
"created": 1748228315,
"data": [
{
"b64_json": "iVBORw0KGgoAAA..."
}
],
"usage": {
"input_tokens": 252,
"output_tokens": 4160,
"total_tokens": 4412,
"input_tokens_details": {
"image_tokens": 194,
"text_tokens": 58
}
}
}