SiliconFlow
API手册

创建图片生成请求

根据给定提示词生成图片。生成图片的 URL 有效期为一小时,请及时下载保存,以免因 URL 过期造成问题。

POST
/images/generations
AuthorizationBearer <token>required

添加 Header 'Authorization: Bearer {账户 API Key}' 进行鉴权

In: header

modelstringrequired

对应的模型名称。为更好地提升服务质量,我们会对本服务提供的模型进行定期变更,包括但不限于模型上下线和模型服务能力的调整。在可行的情况下,我们会通过公告或消息推送等适当方式通知您此类变更。完整可用模型列表请查看 Models

Example"Qwen/Qwen-Image-Edit-2509"
promptstringrequired

用于生成图片的文本提示词。

Example"an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea"
negative_prompt负面提示词

指定不希望在生成图片中出现的内容。

image_size图片尺寸,格式为 [width]x[height]。

图片分辨率,格式为 "widthxheight"。为确保最佳质量,强烈建议使用对应模型的推荐值。Qwen/Qwen-Image-Edit-2509 和 Qwen/Qwen-Image-Edit 不支持此字段,其他模型为必填项。 推荐值:

  • Kolor 模型:
    • "1024x1024" (1:1)
    • "960x1280" (3:4)
    • "768x1024" (3:4)
    • "720x1440" (1:2)
    • "720x1280" (9:16)
  • Qwen-Image 模型:
    • "1328x1328" (1:1)
    • "1664x928" (16:9)
    • "928x1664" (9:16)
    • "1472x1140" (4:3)
    • "1140x1472" (3:4)
    • "1584x1056" (3:2)
    • "1056x1584" (2:3)
batch_size生成图片数量

输出图片数量。仅适用于 Kwai-Kolors/Kolors。

Default1
Range1 <= value <= 4
seedSeed

随机种子,用于控制生成过程的随机性。使用相同的种子值可以生成相似的图片。

Rangevalue <= 9999999999
num_inference_stepsNumber Inference Steps

推理步数。步数越多,生成质量通常越高,但耗时也更长。

Default20
Range1 <= value <= 100
guidance_scaleGuidance Scale

该值用于控制生成图片与给定提示词的匹配程度。值越高,生成图片越倾向于严格匹配文本提示词;值越低,生成图片越具创意和多样性,可能包含更多意外元素。仅适用于 Kwai-Kolors/Kolors。

Default7.5
Rangevalue <= 20
cfgCFG Scale

CFG(Classifier-Free Guidance)是一种通过平衡精确度和创造性来调整生成输出与输入提示词匹配程度的技术。该字段仅适用于 Qwen/Qwen-Image 模型。对于生成包含文本的图片,CFG 值必须大于 1。官方配置使用 50 步、CFG 4.0。当 CFG 设置过小时,几乎无法生成文本。

Range0.1 <= value <= 20
imageUpload Image

用于上传的图片可以是 base64 格式或 URL。

Value in"data:image/png;base64, XXX" | "img_url"
Example"https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641"
image2Upload Image

用于上传的图片可以是 base64 格式或 URL。此字段仅适用于 Qwen/Qwen-Image-Edit-2509。

Value in"data:image/png;base64, XXX" | "img_url"
Example"https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641"
image3Upload Image

用于上传的图片可以是 base64 格式或 URL。此字段仅适用于 Qwen/Qwen-Image-Edit-2509。

Value in"data:image/png;base64, XXX" | "img_url"
Example"https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641"

Response Body

模型响应。响应头中包含 x-siliconcloud-trace-id 字段,作为请求的唯一追踪标识,便于日志查询和问题排查。

TypeScript Definitions

Use the response body type in TypeScript.

imagesarray<object>
timingsobject
seedinteger

curl --request POST \
  --url https://api.siliconflow.cn/v1/images/generations \
  --header 'Authorization: Bearer YOUR-API-KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "Kwai-Kolors/Kolors",
  "prompt": "an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea",
  "image_size": "1024x1024",
  "batch_size": 1,
  "num_inference_steps": 20,
  "guidance_scale": 7.5
}'
import requests
url = "https://api.siliconflow.cn/v1/images/generations"
payload = {
    "model": "Kwai-Kolors/Kolors",
    "prompt": "an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea",
    "image_size": "1024x1024",
    "batch_size": 1,
    "num_inference_steps": 20,
    "guidance_scale": 7.5
}
headers = {
    "Authorization": "Bearer YOUR-API-KEY",
    "Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer YOUR-API-KEY',
    'Content-Type': 'application/json'
  },
  body: '{"model":"Kwai-Kolors/Kolors",
  "prompt":"an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea",
  "image_size":"1024x1024",
  "batch_size":1,
  "num_inference_steps":20,
  "guidance_scale":7.5
};

fetch('https://api.siliconflow.cn/v1/images/generations', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
curl --request POST \
  --url https://api.siliconflow.cn/v1/images/generations \
  --header 'Authorization: Bearer YOUR-API-KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "Kwai-Kolors/Kolors",
  "prompt": "an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea",
  "image_size": "1024x1024",
  "batch_size": 1,
  "num_inference_steps": 20,
  "guidance_scale": 7.5,
  "image": "https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641"
}'
import requests
url = "https://api.siliconflow.cn/v1/images/generations"
payload = {
    "model": "Kwai-Kolors/Kolors",
    "prompt": "an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea",
    "image_size": "1024x1024",
    "batch_size": 1,
    "num_inference_steps": 20,
    "guidance_scale": 7.5,
    "image": "https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641"
}
headers = {
    "Authorization": "Bearer YOUR-API-KEY",
    "Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer YOUR-API-KEY',
    'Content-Type': 'application/json'
  },
  body: '{"model":"Kwai-Kolors/Kolors",
  "prompt":"an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea",
  "image_size":"1024x1024",
  "batch_size":1,
  "num_inference_steps":20,
  "guidance_scale":7.5
  "image":"https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641"}'
};

fetch('https://api.siliconflow.cn/v1/images/generations', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
curl --request POST \
  --url https://api.siliconflow.cn/v1/images/generations \
  --header 'Authorization: Bearer YOUR-API-KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "Qwen/Qwen-Image-Edit-2509",
  "prompt": "an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea",
  "num_inference_steps": 20,
  "cfg": 4,
  "image": "https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641",
  "image2": "https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641",
  "image3": "https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641"
}'
import requests

url = "https://api.siliconflow.cn/v1/images/generations"

payload = {
    "model": "Qwen/Qwen-Image-Edit-2509",
    "prompt": "an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea",
    "num_inference_steps": 20,
    "cfg": 4,
    "image": "https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641",
    "image2": "https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641",
    "image3": "https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641"
}
headers = {
    "Authorization": "Bearer YOUR-API-KEY",
    "Content-Type": "application/json"
}

response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer YOUR-API-KEY',
    'Content-Type': 'application/json'
  },
  body: '{"model":"Qwen/Qwen-Image-Edit-2509",
  "prompt":"an island near sea, with seagulls, moon shining over the sea, light house, boats int he background, fish flying over the sea",
  "num_inference_steps":20,
  "cfg":4,
  "image":"https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641",
  "image2":"https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641",
  "image3":"https://inews.gtimg.com/om_bt/Os3eJ8u3SgB3Kd-zrRRhgfR5hUvdwcVPKUTNO6O7sZfUwAA/641"}'
};

fetch('https://api.siliconflow.cn/v1/images/generations', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
{
  "images": [
    {
      "url": "string"
    }
  ],
  "timings": {
    "inference": 0.1
  },
  "seed": 0
}
{
  "code": 20012,
  "message": "string",
  "data": "string"
}
"Invalid token"
"Forbidden"
"404 page not found"
{
  "message": "Request was rejected due to rate limiting. If you want more, please contact contact@siliconflow.cn. Details:TPM limit reached.",
  "data": "string"
}
{
  "code": 50505,
  "message": "Model service overloaded. Please try again later.",
  "data": "string"
}
"string"