Stable Diffusion with LoRAs

fal-ai/lora
Commercial use

API documentation

Text To Image

Calling the API

The API follows common HTTP semantics and should work with the language of your preference. Below you will find the API endpoint and some code snippets to help you get started:

https://fal.run/fal-ai/lora
import * as fal from "@fal-ai/serverless-client";

const result = await fal.subscribe("fal-ai/lora", {
  input: {
    model_name: "stabilityai/stable-diffusion-xl-base-1.0",
    prompt: "Photo of a european medieval 40 year old queen, silver hair, highly detailed face, detailed eyes, head shot, intricate crown, age spots, wrinkles"
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      update.logs.map((log) => log.message).forEach(console.log);
    }
  },
});

For requests that take longer than several seconds, checkout our queue and webhook features. Our JS and Python clients use the queue behind the scenes. Head to our client page in our documenation site to read more about our Python and Javascript clients.

Input

model_name*string

URL or HuggingFace ID of the base model to generate the image.

Examples:

  • "stabilityai/stable-diffusion-xl-base-1.0"
  • "runwayml/stable-diffusion-v1-5"
  • "SG161222/Realistic_Vision_V2.0"
variantstring

The variant of the model to use for huggingface models, e.g. 'fp16'.

prompt*string

The prompt to use for generating the image. Be as descriptive as possible for best results.

Examples:

  • "Photo of a european medieval 40 year old queen, silver hair, highly detailed face, detailed eyes, head shot, intricate crown, age spots, wrinkles"
  • "Photo of a classic red mustang car parked in las vegas strip at night"
negative_promptstring

The negative prompt to use.Use it to address details that you don't want in the image. This could be colors, objects, scenery and even the small details (e.g. moustache, blurry, low resolution). Default value: ""

Examples:

  • "cartoon, painting, illustration, (worst quality, low quality, normal quality:2)"
  • "nsfw, cartoon, (epicnegative:0.9)"
loraslist<LoraWeight>

The LoRAs to use for the image generation. You can use any number of LoRAs and they will be merged together to generate the final image.

embeddingslist<Embedding>

The embeddings to use for the image generation. Only a single embedding is supported at the moment. The embeddings will be used to map the tokens in the prompt to the embedding weights.

controlnetslist<ControlNet>

The control nets to use for the image generation. You can use any number of control nets and they will be applied to the image at the specified timesteps.

controlnet_guess_modeboolean

If set to true, the controlnet will be applied to only the conditional predictions.

ip_adapterlist<IPAdapter>

The IP adapter to use for the image generation.

image_encoder_pathstring

The path to the image encoder model to use for the image generation.

Examples:

  • "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
image_encoder_subfolderstring

The subfolder of the image encoder model to use for the image generation.

Examples:

    image_encoder_weight_namestring

    The weight name of the image encoder model to use for the image generation. Default value: "pytorch_model.bin"

    Examples:

    • "pytorch_model.bin"
    ic_light_model_urlstring

    The URL of the IC Light model to use for the image generation.

    ic_light_image_urlstring

    The URL of the IC Light model image to use for the image generation.

    seedinteger

    The same seed and the same prompt given to the same version of Stable Diffusion will output the same image every time.

    image_sizeImageSize | Enum

    The size of the generated image. You can choose between some presets or custom height and width that must be multiples of 8. Default value: square_hd

    Possible values: "square_hd", "square", "portrait_4_3", "portrait_16_9", "landscape_4_3", "landscape_16_9"

    num_inference_stepsinteger

    Increasing the amount of steps tells Stable Diffusion that it should take more steps to generate your final result which can increase the amount of detail in your image. Default value: 30

    guidance_scalefloat

    The CFG (Classifier Free Guidance) scale is a measure of how close you want the model to stick to your prompt when looking for a related image to show you. Default value: 7.5

    clip_skipinteger

    Skips part of the image generation process, leading to slightly different results. This means the image renders faster, too.

    schedulerSchedulerEnum

    Scheduler / sampler to use for the image denoising process.

    Possible values: "DPM++ 2M", "DPM++ 2M Karras", "DPM++ 2M SDE", "DPM++ 2M SDE Karras", "Euler", "Euler A", "LCM", "DDIM"

    image_formatImageFormatEnum

    The format of the generated image. Default value: "png"

    Possible values: "jpeg", "png"

    num_imagesinteger

    Number of images to generate in one request. Note that the higher the batch size, the longer it will take to generate the images. Default value: 1

    enable_safety_checkerboolean

    If set to true, the safety checker will be enabled.

    tile_widthinteger

    The size of the tiles to be used for the image generation. Default value: 4096

    tile_heightinteger

    The size of the tiles to be used for the image generation. Default value: 4096

    tile_stride_widthinteger

    The stride of the tiles to be used for the image generation. Default value: 2048

    tile_stride_heightinteger

    The stride of the tiles to be used for the image generation. Default value: 2048

    debug_latentsboolean

    If set to true, the latents will be saved for debugging.

    debug_per_pass_latentsboolean

    If set to true, the latents will be saved for debugging per pass.

    Input sample:
    {
      "model_name": "stabilityai/stable-diffusion-xl-base-1.0",
      "prompt": "Photo of a european medieval 40 year old queen, silver hair, highly detailed face, detailed eyes, head shot, intricate crown, age spots, wrinkles",
      "negative_prompt": "cartoon, painting, illustration, (worst quality, low quality, normal quality:2)",
      "loras": [
        {
          "path": "https://civitai.com/api/download/models/135931",
          "scale": 1
        }
      ],
      "embeddings": [
        {
          "path": "https://storage.googleapis.com/falserverless/style_lora/emb_our_test_1.safetensors",
          "tokens": [
            "<s0>",
            "<s1>"
          ]
        }
      ],
      "controlnets": [
        {
          "path": "diffusers/controlnet-canny-sdxl-1.0",
          "image_url": "https://storage.googleapis.com/falserverless/model_tests/controlnet_sdxl/canny-edge.resized.jpg",
          "conditioning_scale": 1,
          "end_percentage": 1
        }
      ],
      "ip_adapter": [
        {
          "ip_adapter_image_url": "https://storage.googleapis.com/falserverless/model_tests/controlnet_sdxl/robot.jpeg",
          "path": "h94/IP-Adapter",
          "model_subfolder": "sdxl_models",
          "weight_name": "ip-adapter-plus_sdxl_vit-h.safetensors",
          "scale": 1
        }
      ],
      "image_encoder_path": "laion/CLIP-ViT-H-14-laion2B-s32B-b79K",
      "image_encoder_weight_name": "pytorch_model.bin",
      "image_size": "square_hd",
      "num_inference_steps": 30,
      "guidance_scale": 7.5,
      "image_format": "jpeg",
      "num_images": 1,
      "tile_width": 4096,
      "tile_height": 4096,
      "tile_stride_width": 2048,
      "tile_stride_height": 2048
    }

    Output

    images*list<Image>

    The generated image files info.

    seed*integer

    Seed of the generated Image. It will be the same value of the one passed in the input or the randomly generated that was used in case none was passed.

    has_nsfw_concepts*list<boolean>

    Whether the generated images contain NSFW concepts.

    debug_latentsFile

    The latents saved for debugging.

    debug_per_pass_latentsFile

    The latents saved for debugging per pass.

    Output sample:
    {
      "images": [
        {
          "url": "",
          "content_type": "image/png",
          "file_name": "z9RV14K95DvU.png",
          "file_size": 4404019,
          "width": 1024,
          "height": 1024
        }
      ],
      "debug_latents": {
        "url": "",
        "content_type": "image/png",
        "file_name": "z9RV14K95DvU.png",
        "file_size": 4404019
      },
      "debug_per_pass_latents": {
        "url": "",
        "content_type": "image/png",
        "file_name": "z9RV14K95DvU.png",
        "file_size": 4404019
      }
    }

    Error types

    Some errors may also contain a JSON payload with additional details. In this section you can find the possible error types and their properties.

    ValidationError

    When input validation fails, the API will response with a 422 status and an array of ValidationError object in the response body. The ValidationError object will contain a list of errors, each with a loc (location) attribute that indicates the path to the invalid input, and a msg (message) attribute that describes the error.

    msg*string
    type*string

    HTTPValidationError

    detaillist<ValidationError>

    Types

    IPAdapter

    ip_adapter_image_url*string | list<string>

    URL of the image to be used as the IP adapter.

    ip_adapter_mask_urlstring

    The mask to use for the IP adapter. When using a mask, the ip-adapter image size and the mask size must be the same

    path*string

    URL or the path to the IP adapter weights.

    Examples:

    • "h94/IP-Adapter"
    model_subfolderstring

    Subfolder in the model directory where the IP adapter weights are stored.

    Examples:

    • "sdxl_models"
    weight_namestring

    Name of the weight file.

    Examples:

    • "ip-adapter-plus_sdxl_vit-h.safetensors"
    insight_face_model_pathstring

    URL or the path to the InsightFace model weights.

    scalefloat

    The scale of the IP adapter weight. This is used to scale the IP adapter weight before merging it with the base model. Default value: 1

    scale_jsonScale Json

    The scale of the IP adapter weight. This is used to scale the IP adapter weight before merging it with the base model.

    unconditional_noising_factorfloat

    The factor to apply to the unconditional noising of the IP adapter.

    File

    url*string

    The URL where the file can be downloaded from.

    content_typestring

    The mime type of the file.

    Examples:

    • "image/png"
    file_namestring

    The name of the file. It will be auto-generated if not provided.

    Examples:

    • "z9RV14K95DvU.png"
    file_sizeinteger

    The size of the file in bytes.

    file_datastring

    File data

    ImageSize

    widthinteger

    The width of the generated image. Default value: 512

    heightinteger

    The height of the generated image. Default value: 512

    LoraWeight

    path*string

    URL or the path to the LoRA weights.

    Examples:

    • "https://civitai.com/api/download/models/135931"
    • "https://filebin.net/3chfqasxpqu21y8n/my-custom-lora-v1.safetensors"
    scalefloat

    The scale of the LoRA weight. This is used to scale the LoRA weight before merging it with the base model. Default value: 1

    Embedding

    path*string

    URL or the path to the embedding weights.

    Examples:

    • "https://storage.googleapis.com/falserverless/style_lora/emb_our_test_1.safetensors"
    tokenslist<string>

    The tokens to map the embedding weights to. Use these tokens in your prompts. Default value: <s0>,<s1>

    Image

    Represents an image file.

    url*string

    The URL where the file can be downloaded from.

    content_typestring

    The mime type of the file.

    Examples:

    • "image/png"
    file_namestring

    The name of the file. It will be auto-generated if not provided.

    Examples:

    • "z9RV14K95DvU.png"
    file_sizeinteger

    The size of the file in bytes.

    file_datastring

    File data

    widthinteger

    The width of the image in pixels.

    heightinteger

    The height of the image in pixels.

    ControlNet

    path*string

    URL or the path to the control net weights.

    Examples:

    • "diffusers/controlnet-canny-sdxl-1.0"
    variantstring

    The optional variant if a Hugging Face repo key is used.

    image_url*string

    URL of the image to be used as the control net.

    Examples:

    • "https://storage.googleapis.com/falserverless/model_tests/controlnet_sdxl/canny-edge.resized.jpg"
    mask_urlstring

    The mask to use for the controlnet. When using a mask, the control image size and the mask size must be the same and divisible by 32.

    conditioning_scalefloat

    The scale of the control net weight. This is used to scale the control net weight before merging it with the base model. Default value: 1

    start_percentagefloat

    The percentage of the image to start applying the controlnet in terms of the total timesteps.

    end_percentagefloat

    The percentage of the image to end applying the controlnet in terms of the total timesteps. Default value: 1

    ip_adapter_indexinteger

    The index of the IP adapter to be applied to the controlnet. This is only needed for InstantID ControlNets.