SiliconFlow

创建图片生成请求

Creates an image response for the given prompt. The URL for the generated image is valid for one hour. Please make sure to download and store it promptly to avoid any issues due to URL expiration.

POST
/images/generations
AuthorizationBearer <token>required

Use the following format for authentication: Bearer

In: header

modelstringrequired

Corresponding Model Name. To better enhance service quality, we will make periodic changes to the models provided by this service, including but not limited to model on/offlining and adjustments to model service capabilities. We will notify you of such changes through appropriate means such as announcements or message pushes where feasible. For a complete list of available models, please check the 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_promptNegative Prompt

negative prompt

image_sizeImage size, format is [width]x[height].

Image resolution in "widthxheight" format (Required). To ensure optimal quality, using the recommended values for your model is strongly advised. Qwen/Qwen-Image-Edit-2509 and Qwen/Qwen-Image-Edit not support this field. Recommended Values:

  • For Kolor model:
    • "1024x1024" (1:1)
    • "960x1280" (3:4)
    • "768x1024" (3:4)
    • "720x1440" (1:2)
    • "720x1280" (9:16)
  • For Qwen-Image model:
    • "1328x1328" (1:1)
    • "1664x928" (16:9)
    • "928x1664" (9:16)
    • "1472x1140" (4:3)
    • "1140x1472" (3:4)
    • "1584x1056" (3:2)
    • "1056x1584" (2:3)
batch_sizeNumber Images

number of output images. Only applicable to Kwai-Kolors/Kolors.

Default1
Range1 <= value <= 4
seedSeed
Rangevalue <= 9999999999
num_inference_stepsNumber Inference Steps

number of inference steps

Default20
Range1 <= value <= 100
guidance_scaleGuidance Scale

This value is used to control the degree of match between the generated image and the given prompt. The higher the value, the more the generated image will tend to strictly match the text prompt. The lower the value, the more creative and diverse the generated image will be, potentially containing more unexpected elements. Only applicable to Kwai-Kolors/Kolors.

Default7.5
Rangevalue <= 20
cfgCFG Scale

CFG (Classifier-Free Guidance) is a technique that adjusts how closely generated outputs follow input prompts by balancing precision and creativity. This field is only applicable to Qwen/Qwen-Image models. For text generation scenarios, the CFG value must be greater than 1. The official configuration uses 50 steps with CFG 4.0. When CFG is set too small, it becomes nearly impossible to generate text.

Range0.1 <= value <= 20
imageUpload Image

The image used for uploading an image can be in base64 format or a URL.

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

The image used for uploading an image can be in base64 format or a URL. This field is only applicable to 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

The image used for uploading an image can be in base64 format or a URL. This field is only applicable to 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

curl -X POST "https://api.siliconflow.cn/v1/images/generations" \
  -H "Content-Type: application/json" \
  -d '{
    "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"
  }'
const body = JSON.stringify({
  "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"
})

fetch("https://api.siliconflow.cn/v1/images/generations", {
  body
})
package main

import (
  "fmt"
  "net/http"
  "io/ioutil"
  "strings"
)

func main() {
  url := "https://api.siliconflow.cn/v1/images/generations"
  body := strings.NewReader(`{
    "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"
  }`)
  req, _ := http.NewRequest("POST", url, body)
  req.Header.Add("Content-Type", "application/json")
  res, _ := http.DefaultClient.Do(req)
  defer res.Body.Close()
  body, _ := ioutil.ReadAll(res.Body)

  fmt.Println(res)
  fmt.Println(string(body))
}
import requests

url = "https://api.siliconflow.cn/v1/images/generations"
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"
}
response = requests.request("POST", url, json = body, headers = {
  "Content-Type": "application/json"
})

print(response.text)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.time.Duration;
import java.net.http.HttpRequest.BodyPublishers;

var body = BodyPublishers.ofString("""{
  "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"
}""");
HttpClient client = HttpClient.newBuilder()
  .connectTimeout(Duration.ofSeconds(10))
  .build();

HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
  .uri(URI.create("https://api.siliconflow.cn/v1/images/generations"))
  .header("Content-Type", "application/json")
  .POST(body)
  .build();

try {
  HttpResponse<String> response = client.send(requestBuilder.build(), BodyHandlers.ofString());
  System.out.println("Status code: " + response.statusCode());
  System.out.println("Response body: " + response.body());
} catch (Exception e) {
  e.printStackTrace();
}
using System;
using System.Net.Http;
using System.Text;

var body = new StringContent("""
{
  "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"
}
""", Encoding.UTF8, "application/json");

var client = new HttpClient();
var response = await client.PostAsync("https://api.siliconflow.cn/v1/images/generations", body);
var responseBody = await response.Content.ReadAsStringAsync();
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"