Stable Diffusion XL 1.0

The SDXL model is the official upgrade to the v1.5 model. The model is released as open-source software

~6.34s
~$0.008
 1import requests
 2import json
 3
 4url = "https://api.segmind.com/v1/sdxl1.0-txt2img"
 5headers = {
 6    "x-api-key": "YOUR_API_KEY",
 7    "Content-Type": "application/json"
 8}
 9
10data = {
11    "prompt": "cinematic film still, 4k, realistic, ((cinematic photo:1.3)) of panda wearing a blue spacesuit, sitting in a bar, Fujifilm XT3, long shot, ((low light:1.4)), ((looking straight at the camera:1.3)), upper body shot, somber, shallow depth of field, vignette, highly detailed, high budget Hollywood movie, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
12    "negative_prompt": "ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft",
13    "style": "base",
14    "samples": 1,
15    "scheduler": "UniPC",
16    "num_inference_steps": 25,
17    "guidance_scale": 8,
18    "strength": 0.2,
19    "high_noise_fraction": 0.8,
20    "seed": 468685,
21    "img_width": 896,
22    "img_height": 1152,
23    "refiner": true,
24    "base64": false
25}
26
27response = requests.post(url, headers=headers, json=data)
28
29if response.status_code == 200:
30    result = response.json()
31    print(json.dumps(result, indent=2))
32else:
33    print(f"Error: {response.status_code}")
34    print(response.text)

API Endpoint

POSThttps://api.segmind.com/v1/sdxl1.0-txt2img

Parameters

promptrequired
string

Prompt to render

base64optional
boolean

Base64 encoding of the output image.

Default: false
guidance_scaleoptional
number

Scale for classifier-free guidance

Default: 7.5Range: 1 - 25
high_noise_fractionoptional
number

Number of inference steps to be run on each expert

Default: 0.8Range: 0 - 1
img_heightoptional
integer

Image height can be between 512 and 2048 in multiples of 8

Default: 1024
img_widthoptional
integer

Image width can be between 512 and 2048 in multiples of 8

Default: 1024
negative_promptoptional
string

Prompts to exclude, eg. 'bad anatomy, bad hands, missing fingers'

num_inference_stepsoptional
integer

Number of denoising steps.

Default: 25Range: 20 - 100
refineroptional
boolean

If yes, improves the quality of the output. Note: Does not work when high noise fraction is 1.

Default: true
samplesoptional
integer

Number of samples to generate.

Default: 1Range: 1 - 4
scheduleroptional
string

Type of scheduler.

Default: "UniPC"
Allowed values (12 total):
"DDIM""DPM Multi""DPM Single""Euler a""Euler""Heun""DPM2 a Karras""DPM2 Karras""LMS""PNDM"+2 more
seedoptional
integer

Seed for image generation.

Default: -1Range: -1 - 999999999999999
strengthoptional
number

How much to transform the reference image

Default: 0.2Range: 0.1 - 1
styleoptional
string

Styles for Stable Diffusion.

Default: "base"
Allowed values (104 total):
"base""3d-model""analog film""anime""cinematic""comic book""craft clay""digital art""enhance""fantasy art"+94 more

Response Type

Returns: Text/JSON

Common Error Codes

The API returns standard HTTP status codes. Detailed error messages are provided in the response body.

400

Bad Request

Invalid parameters or request format

401

Unauthorized

Missing or invalid API key

403

Forbidden

Insufficient permissions

404

Not Found

Model or endpoint not found

406

Insufficient Credits

Not enough credits to process request

429

Rate Limited

Too many requests

500

Server Error

Internal server error

502

Bad Gateway

Service temporarily unavailable

504

Timeout

Request timed out