ai_diffusion

An authenticated client can post a request to Stable Diffusion v1.4

Stable Diffusion comes with two flavors to produce images:

  • TXT2IMG: a text to image generation AI. Input text and a few additional parameters.

  • IMG2IMG: an image to image generation AI. Input a guiding image (full URI of the image), additional text, and a few additional parameters

Check more details about Stable Diffusion and its parameters on wikipedia

Get the JSON config file for this AI

GET https://opensourceais.com/api/v1/public/config/diffusion

You should not need to call this endpoint. This is just a FYI to understand all input parameters sent to the AI.

{
    "data": {
        "engine": "diffusion",
        "version": "1.4.0",
        "name": "Stable Diffusion v1.4",
        "description": "Text to Image",
        "isFree": false,
        "requiresGPU": true,
        "aParam": [
            {
                "in": "word",
                "out": "--prompt",
                "isMandatory": true,
                "type": "string",
                "default": null,
                "ui": {
                    "title": "Input (text and/or image)",
                    "placeholder": "eg: gold coin from rome 100 BC, full size",
                    "widget": "uiEdit",
                    "column": 1
                }
            },
            {
                "in": "url_upload",
                "out": "-filename",
                "isMandatory": false,
                "type": "string",
                "default": null,
                "ui": {
                    "widget": "uiSelectPicture",
                    "column": 1
                }
            },
            {
                "in": "steps",
                "out": "--ddim_steps",
                "isMandatory": true,
                "type": "int",
                "default": 20,
                "freeAccess": {
                    "$max": 100
                },
                "ui": {
                    "title": "Step Count",
                    "tooltip": "",
                    "min": 1,
                    "max": 200,
                    "unit": "",
                    "widget": "uiRangeSlider",
                    "column": 1
                }
            },
            {
                "in": "guidance",
                "out": "--scale",
                "isMandatory": true,
                "type": "float",
                "default": 7.5,
                "ui": {
                    "title": "Guidance scale",
                    "tooltip": "",
                    "displayAsPercent": true,
                    "unit": "",
                    "min": 1,
                    "max": 12,
                    "widget": "uiRangeSlider",
                    "column": 1,
                    "conditional": {
                        "$null": "url_upload"
                    }
                }
            },
            {
                "in": "strength",
                "out": "--strength",
                "isMandatory": true,
                "type": "float",
                "default": 0.5,
                "ui": {
                    "title": "Strength",
                    "tooltip": "",
                    "displayAsPercent": true,
                    "unit": "",
                    "min": 0,
                    "max": 1,
                    "widget": "uiRangeSlider",
                    "column": 1,
                    "conditional": {
                        "$exist": "url_upload"
                    }
                }
            },
            {
                "in": "width",
                "out": "--W",
                "isMandatory": true,
                "type": "int",
                "default": 512,
                "accept": {
                    "$in": [
                        320,
                        384,
                        448,
                        512,
                        640,
                        768
                    ],
                    "display": [
                        "320x320",
                        "384x384",
                        "448x448",
                        "512x512",
                        "640x640",
                        "768x768"
                    ]
                },
                "freeAccess": {
                    "$max": 512
                },
                "ui": {
                    "title": "Output resolution",
                    "unit": "px",
                    "widget": "uiMultiToggle",
                    "autofill": [
                        {
                            "in": "height",
                            "out": "--H"
                        }
                    ],
                    "column": 2
                }
            },
            {
                "in": "height",
                "out": "--H",
                "isMandatory": true,
                "type": "int",
                "default": 512,
                "accept": {
                    "$in": [
                        320,
                        384,
                        448,
                        512,
                        640,
                        768
                    ]
                },
                "freeAccess": {
                    "$max": 512
                },
                "ui": {
                    "unit": "px"
                }
            },
            {
                "in": "cimg",
                "out": "--n_samples",
                "isMandatory": true,
                "type": "int",
                "default": 1,
                "accept": {
                    "$in": [
                        1,
                        2,
                        3,
                        4
                    ],
                    "display": [
                        "1",
                        "2",
                        "3",
                        "4"
                    ]
                },
                "ui": {
                    "title": "Number of images to generate",
                    "widget": "uiMultiToggle",
                    "column": 2
                }
            },
            {
                "in": "saveinterval",
                "out": "--se",
                "isMandatory": true,
                "type": "int",
                "default": 2,
                "freeAccess": {
                    "$max": 20
                },
                "ui": {
                    "title": "Save every",
                    "tooltip": "",
                    "min": 1,
                    "max": 20,
                    "unit": "",
                    "widget": "uiRangeSlider",
                    "column": 2
                }
            },
            {
                "in": "seed",
                "out": "--seed",
                "isMandatory": true,
                "type": "function",
                "default": "$random"
            },
            {
                "in": "model",
                "out": "--ckpt",
                "isMandatory": true,
                "type": "string",
                "default": "sd-v1-4.ckpt"
            },
            {
                "in": "output",
                "out": "--output",
                "isMandatory": true,
                "type": "function",
                "default": "$output_uid.ext"
            }
        ]
    }
}

Post a request to Stable Diffusion via OpenSourceAIs

POST https://opensourceais.com/api/v1/private/client/ai/diffusion

Request Body

Name
Type
Description

width

Number

The width of the output image. Defaults to 320

height

Number

The height of the output image. Defaults to 320

steps

Number

The number of steps requested for generating the output image. High number of steps cost more GPU compute. Defaults to 20. Should not exceed 200.

seed

Number

A random number between 1 and 1,000,000 used by the TXT2IMG generation. Same seed and exact same params delivers same output. Defaults to 1. Should send random values for better experience.

word*

String

A text input to tell the AI what to generate.

url_upload

String

A well formed URI starting with https://... and accessing a PNG or JPG image. Note that if the image is not of the width and height size passed in parameters, it will be automatically cropped or resized.

strength

Float

A float between 0 and 1, corresponding to a % of strength applied for the IMG2IMG generation. Defaults to 0.75.

guidance

Float

A float between 0.1 and 10, corresponding to the guidance scale applied for the TXT2IMG generation. Defaults to 7.5.

cimg

Number

The number of images to produce. Defaults to 1. Note that more images to produce will cost proportionally more in GPU compute.

{
    "data": {
        "uid": 1678361974000,
        "created_at": "2023-03-09T11:39:44.000Z"
    }
}

Last updated