/api/sd/txt2img
POST /api/sd/txt2img
This interface provides a service for generating images from text.
Header Parameters
- Authorization string required
- Bearer DAN_API_KEY.
- Public anonymous DAN_API_KEY is:
sk-000000000000000000000000000000000000000000000000
- Please refer to the Authentication section on how to obtain a private DAN_API_KEY.
Example: Bearer sk-000000000000000000000000000000000000000000000000 - Content-Type string required
application/json is required
Example: application/json - Accept stringExample: application/json
- application/json
Request Body
- prompt string required
A positive prompt that describes what you want the image to be.
- sampler_name string required
The name of the sampling algorithm used. refer to the
Introduction section
for supported list values - model string required
The model used to generate the image. refer to the
Introduction section
for supported list values - width integer required
The desired width of the resulting image. Valid range is [8, 1024].
- height integer required
The desired height of the resulting image. Valid range is [8, 1024].
- loras array[]
- A list of LoRAs to be applied and their weights.
- Format example
[
["XXXXXXXX", 0.5],
["XXXXXXXX", 0.6]
]- "XXXX" mean LoRA value. Such like "62efe75048d55a096a238c6e8c4e12d61b36bf59e388a90589335f750923954c".
- Refer to the Introduction section for supported list values.
- seed integer
-1 for a random seed.
- steps integer
Number of inference steps. Valid range is [20, 60], default 20.
- cfg_scale integer
A classifier-free guidance scale; smaller values result in higher quality images, and larger values yield images closer to the provided prompt. Valid range is [1, 30].
- negative_prompt string
A negative prompt that describes what you don't want in the image.
control_net object[]
Optional. An array of control net parameters. Theoretically speaking, multiple control net can be applied simultaneously, but currently only up to 1 control net is supported, if you specify more than 1 set of paramters, the rest (i.e. not the first one) will be ignored.
Array [image string requiredThe reference image file, encoded in base64
model string requiredThe control net model. Valid options are:
sd15_canny
andsd15_openpose
.preprocess string requiredHow the reference image should be preprocessed, you can specify the preprocess method name. Valid options are:
canny
andopenopse
.preprocess_param1 unknownOptional. Some control net model (e.g. sd15_canny) requires parameters, this is the first parameter. See the table below. If you don't known what to fill in here, just leave it undefined.
Control net model Type Description sd15_canny number The first threshold of canny algorithm. For more information, see opencv doc sd15_openpose Ignored Ignored preprocess_param2 unknownOptional. Some control net model (e.g. sd15_canny) requires parameters, this is the second parameter. See the table below. If you don't known what to fill in here, just leave it undefined.
Control net model Type Description sd15_canny number The second threshold of canny algorithm. For more information, see opencv doc sd15_openpose Ignored Ignored weight numberBefore merging control net into the main SD model, all weights will be scaled by this value. Valid range is [0, 2], default value is 1.
resize_mode numberIf control image's dimension does not equal to target dimension, stable diffusion will resize the control image. 0 means just resize, 1 means resize and crop, 2 means resize and fill, otherwise use default value: 0.
guidance_start numberThe control net will be applied in [guidance_start, guidance_end] percents inference steps. Valid range is [0, 1], default: 0.
guidance_end numberThe control net will be applied in [guidance_start, guidance_end] percents inference steps. Valid range is [0, 1], default: 1.
guessmode boolOptional. Default: false. If true, you can just remove all prompts, and then the control net encoder will recognize the content of the input control map. For this mode, we recommend to use 50 steps and guidance scale between 3 and 5.
]upscale object
Optional, add it if you want to upscale the result.
denoising_strength numberControls the level of denoising; smaller values yield results that are closer to the original generated image, but may be blurry; larger values may lead the output looks different from the original generated image and may looks strange. Valid range is [0, 1], but I recomment you make it between 0.4 and 0.6.
scale numberThe upscale rate. Valid range is (1.0, 2.0].
upscaler stringThe upscaler algorithm name, Currently only Latent is supported.
- 200
The generated image is returned here.
- application/json
- Schema
- Example (from schema)
- Success
Schema
- code integer required
data object required
images string[] requiredstring of base 64 encoded png file. When status = 2, a list of images is returned
taskId string requiredqueuePosition integer requiredThe length of the queue of pending tasks. When status != 0, queuePosition = 0
status integer required0:pending, 1:processing, 2:success, 3:fail
- message string required
{
"code": 0,
"data": {
"images": [
"string"
],
"taskId": "string",
"queuePosition": 0,
"status": 0
},
"message": "string"
}
Success
{
"code": 200,
"data": {
"taskId": "60a4755e-ceb3-4172-8760-28ce47acf04d",
"queuePosition": 0,
"status": 2,
"images": [
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAxHRFWHRwYXJhbWV0ZXJzAEEgY2F0LDxsb3JhOmtvcmVhbkRvbGxMaWtlbmVzc192MTA6MC43PgpTdGVwczogMjAsIFNhbXBsZXI6IERESU0sIENGRyBzY2FsZTogNy4w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