SDXL Lightning API Documentation

The SDXL Lightning API Documentation provides a comprehensive guide to utilizing the full power of the SDXL Lightning API for generating high-quality images from text inputs. With its advanced architecture designed for speed and precision, this API allows developers and businesses to seamlessly integrate text-to-image generation capabilities into their applications, websites, and interactive platforms. Whether you're creating custom artwork, enhancing user engagement, or developing innovative products, this documentation will help you unlock the full potential of the SDXL Lightning model.

Authentication:

To access the SDXL Lightning API, subscribe and obtain an Ocp-Apim-Subscription-Key. Include this key in your request header to authenticate and successfully gain access to the API.

Request Headers:

Content-Type Set to application/json
Cache-Control Recommended to set to no-cache
Ocp-Apim-Subscription-Key YOUR_SUBSCRIPTION_KEY

Request Body

API Parameters: The API POST- https://gateway.appypie.com/inpainting/v1/getImageStream, requires the following parameters:

Name Required Type Description
prompt Yes string The prompts to guide the image generation
negative_prompt No string The prompt or prompts not to guide the image generation.
height No Number, default 1024 the height in pixels of the generated image. This is set to 1024 by default for the best results. Anything below 512 pixels won’t work well.
width No Number, default 1024 The width in pixels of the generated image. This is set to 1024 by default for the best results.
num_inference_steps No Number, default 20, Maximum 20 The number of denoising steps. More denoising steps usually lead to a higher-quality image at the expense of slower inference.
guidance_scale No float, default 5.0 Guidance scale is enabled by setting guidance_scale > 1. A higher guidance scale encourages generating images closely linked to the text prompt, usually at the expense of lower image quality.
seed No 42 The seed is used to reproduce results. Providing the same seed will yield the same image each time. Use “null” for a random number seed.

Example Request Body

JSON

{
    "prompt": "A sunset over a calm ocean, with the golden light of the sun reflecting off the water's surface, creating a serene and warm atmosphere.",

    "negativePrompt": "No storm clouds, no harsh lighting, no unnatural colors, no people, no boats, no urban structures, no artificial lighting, no fog, no excessive contrast, no overexposed highlights, no dark shadows, no cluttered sky, no distracting objects, no cold or blue tones.",
    "height": 1024,
    "width": 1024,
    "num_steps": 20,
    "guidance": 5,
    "seed": 42
}
                

Request Code

Input
   
                POST https://gateway.appypie.com/sdxl_lightning/getImage/v1/getSDXLImageStream HTTP/1.1
                
                Content-Type: application/json
                Cache-Control: no-cache
                
                {
    "prompt": "A sunset over a calm ocean, with the golden light of the sun reflecting off the water's surface, creating a serene and warm atmosphere.",

    "negativePrompt": "No storm clouds, no harsh lighting, no unnatural colors, no people, no boats, no urban structures, no artificial lighting, no fog, no excessive contrast, no overexposed highlights, no dark shadows, no cluttered sky, no distracting objects, no cold or blue tones.",
    "height": 1024,
    "width": 1024,
    "num_steps": 20,
    "guidance": 5,
    "seed": 42
}
                import urllib.request, json
                
                try:
                    url = "https://gateway.appypie.com/sdxl_lightning/getImage/v1/getSDXLImageStream"
                
                    hdr ={
                    # Request headers
                    'Content-Type': 'application/json',
                    'Cache-Control': 'no-cache',
                    }
                
                    # Request body
                    data =  
                    data = json.dumps(data)
                    req = urllib.request.Request(url, headers=hdr, data = bytes(data.encode("utf-8")))
                
                    req.get_method = lambda: 'POST'
                    response = urllib.request.urlopen(req)
                    print(response.getcode())
                    print(response.read())
                    except Exception as e:
                    print(e)
                
                                    
                // Request body
                const body = {
    "prompt": "A sunset over a calm ocean, with the golden light of the sun reflecting off the water's surface, creating a serene and warm atmosphere.",

    "negativePrompt": "No storm clouds, no harsh lighting, no unnatural colors, no people, no boats, no urban structures, no artificial lighting, no fog, no excessive contrast, no overexposed highlights, no dark shadows, no cluttered sky, no distracting objects, no cold or blue tones.",
    "height": 1024,
    "width": 1024,
    "num_steps": 20,
    "guidance": 5,
    "seed": 42
};
                
                fetch('https://gateway.appypie.com/sdxl_lightning/getImage/v1/getSDXLImageStream', {
                        method: 'POST',
                        body: JSON.stringify(body),
                        // Request headers
                        headers: {
                            'Content-Type': 'application/json',
                            'Cache-Control': 'no-cache',}
                    })
                    .then(response => {
                        console.log(response.status);
                        console.log(response.text());
                    })
                    .catch(err => console.error(err));
                
curl -v -X POST "https://gateway.appypie.com/sdxl_lightning/getImage/v1/getSDXLImageStream" -H "Content-Type: application/json" -H "Cache-Control: no-cache" --data-raw "{
                    \"prompt\": \"A sunset over a calm ocean, with the golden light of the sun reflecting off the water's surface, creating a serene and warm atmosphere.\",
                    \"negativePrompt\": \"No storm clouds, no harsh lighting, no unnatural colors, no people, no boats, no urban structures, no artificial lighting, no fog, no excessive contrast, no overexposed highlights, no dark shadows, no cluttered sky, no distracting objects, no cold or blue tones.\",
                    \"height\": 1024,
                    \"width\": 1024,
                    \"num_steps\": 20,
                    \"guidance\": 5,
                    \"seed\": 42
                }"
                
                import java.io.BufferedReader;
                import java.io.InputStreamReader;
                import java.net.HttpURLConnection;
                import java.net.URL;
                import java.net.URLEncoder;
                import java.util.HashMap;
                import java.util.Map;
                import java.io.UnsupportedEncodingException;
                import java.io.DataInputStream;
                import java.io.InputStream;
                import java.io.FileInputStream;
                
                public class HelloWorld {
                
                  public static void main(String[] args) {
                    try {
                        String urlString = "https://gateway.appypie.com/sdxl_lightning/getImage/v1/getSDXLImageStream";
                        URL url = new URL(urlString);
                        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                
                        //Request headers
                    connection.setRequestProperty("Content-Type", "application/json");
                    
                    connection.setRequestProperty("Cache-Control", "no-cache");
                    
                        connection.setRequestMethod("POST");
                
                        // Request body
                        connection.setDoOutput(true);
                        connection
                            .getOutputStream()
                            .write(
                             "{ \"prompt\": \"A sunset over a calm ocean, with the golden light of the sun reflecting off the water's surface, creating a serene and warm atmosphere.\", \"negativePrompt\": \"No storm clouds, no harsh lighting, no unnatural colors, no people, no boats, no urban structures, no artificial lighting, no fog, no excessive contrast, no overexposed highlights, no dark shadows, no cluttered sky, no distracting objects, no cold or blue tones.\", \"height\": 1024, \"width\": 1024, \"num_steps\": 20, \"guidance\": 5, \"seed\": 42 }".getBytes()
                             );
                    
                        int status = connection.getResponseCode();
                        System.out.println(status);
                
                        BufferedReader in = new BufferedReader(
                            new InputStreamReader(connection.getInputStream())
                        );
                        String inputLine;
                        StringBuffer content = new StringBuffer();
                        while ((inputLine = in.readLine()) != null) {
                            content.append(inputLine);
                        }
                        in.close();
                        System.out.println(content);
                
                        connection.disconnect();
                    } catch (Exception ex) {
                      System.out.print("exception:" + ex.getMessage());
                    }
                  }
                }
                
                $url = "https://gateway.appypie.com/sdxl_lightning/getImage/v1/getSDXLImageStream";
                $curl = curl_init($url);
                
                curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
                curl_setopt($curl, CURLOPT_URL, $url);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                
                # Request headers
                $headers = array(
                    'Content-Type: application/json',
                    'Cache-Control: no-cache',);
                curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
                
                # Request body
                $request_body = '{
    "prompt": "A sunset over a calm ocean, with the golden light of the sun reflecting off the water's surface, creating a serene and warm atmosphere.",

    "negativePrompt": "No storm clouds, no harsh lighting, no unnatural colors, no people, no boats, no urban structures, no artificial lighting, no fog, no excessive contrast, no overexposed highlights, no dark shadows, no cluttered sky, no distracting objects, no cold or blue tones.",
    "height": 1024,
    "width": 1024,
    "num_steps": 20,
    "guidance": 5,
    "seed": 42
}';
                curl_setopt($curl, CURLOPT_POSTFIELDS, $request_body);
                
                $resp = curl_exec($curl);
                curl_close($curl);
                var_dump($resp);
                


Response

JSON

Image Streamed 
Check your browser for the image file                    

Error Handling

The SDXL Lightning API returns specific HTTP status codes and response bodies to indicate the success or failure of a request. Developers should implement proper error handling in their applications to manage these responses effectively.

Common Errors

  • 400 Bad Request: The request was poorly formatted, or the required parameters are missing.
  • 401 Unauthorized: Authentication failed, or the necessary authentication credentials were not provided.
  • 500 Internal Server Error: The server encountered an unexpected issue, preventing it from completing the request.

Example Error Response

                {
                    "error": "Invalid prompt parameter"
                }
                

This documentation provides all the essential information for effectively using the SDXL Lightning API. Be sure to replace YOUR_API_KEY with the actual key you received when subscribing to the service.