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.
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) 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
https://api.segmind.com/v1/sdxl-txt2imgParameters
base64optionalbooleanBase64 encoding of the output image.
falseguidance_scaleoptionalnumberScale for classifier-free guidance
img_heightoptionalintegerImage resolution.
img_widthoptionalintegerImage resolution.
negative_promptoptionalstringPrompts to exclude, eg. 'bad anatomy, bad hands, missing fingers'
num_inference_stepsoptionalintegerNumber of denoising steps.
promptoptionalstringPrompt to render
samplesoptionalintegerNumber of samples to generate.
1Range: 1 - 10scheduleroptionalstringType of scheduler.
"dpmpp_sde_ancestral"seedoptionalintegerSeed for image generation.
strengthoptionalnumberHow 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.
Bad Request
Invalid parameters or request format
Unauthorized
Missing or invalid API key
Forbidden
Insufficient permissions
Not Found
Model or endpoint not found
Insufficient Credits
Not enough credits to process request
Rate Limited
Too many requests
Server Error
Internal server error
Bad Gateway
Service temporarily unavailable
Timeout
Request timed out