Stable Diffusion XL 0.9 Serverless API

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

~0.00s
~$0.003
 1import requests
 2import json
 3
 4url = "https://api.segmind.com/v1/sdxl-txt2img"
 5headers = {
 6    "x-api-key": "YOUR_API_KEY",
 7    "Content-Type": "application/json"
 8}
 9
10data = {
11    "prompt": "a beautiful stack of rocks sitting on top of a beach, a picture, red black white golden colors, chakras, packshot, stock photo",
12    "negative_prompt": "asian, african, makeup, fake, cgi, 3d, doll, art, anime, cartoon, illustration, painting, digital, blur, sepia, b&w, unnatural, unreal, photoshop, filter, airbrush, poor anatomy, lr",
13    "samples": 1,
14    "scheduler": "dpmpp_sde_ancestral",
15    "num_inference_steps": 25,
16    "guidance_scale": 8,
17    "strength": 1,
18    "seed": 2784983004,
19    "img_width": 768,
20    "img_height": 768,
21    "base64": false
22}
23
24response = requests.post(url, headers=headers, json=data)
25
26if response.status_code == 200:
27    result = response.json()
28    print(json.dumps(result, indent=2))
29else:
30    print(f"Error: {response.status_code}")
31    print(response.text)

API Endpoint

POSThttps://api.segmind.com/v1/sdxl-txt2img

Parameters

base64optional
boolean

Base64 encoding of the output image.

Default: false
guidance_scaleoptional
number

Scale for classifier-free guidance

Range: 1 - 15
img_heightoptional
integer

Image resolution.

Range: 512 - 1024
img_widthoptional
integer

Image resolution.

Range: 512 - 1024
negative_promptoptional
string

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

num_inference_stepsoptional
integer

Number of denoising steps.

Range: 10 - 40
promptoptional
string

Prompt to render

samplesoptional
integer

Number of samples to generate.

Default: 1Range: 1 - 10
scheduleroptional
string

Type of scheduler.

Allowed values :
"dpmpp_sde_ancestral"
seedoptional
integer

Seed for image generation.

strengthoptional
number

How much to transform the reference image

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