Stable Diffusion with LoRAs

fal-ai/lora
This API is available for 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"
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.

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.

model_architectureModelArchitectureEnum

The architecture of the model to use. If an HF model is used, it will be automatically detected. Otherwise will assume depending on the model name (whether XL is in the name or not).

Possible values: "sd", "sdxl"

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"

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

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",
      "image_encoder_path": "h94/IP-Adapter",
      "image_encoder_subpath": "models/image_encoder",
      "scale": 1
    }
  ],
  "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.

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

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_urlstring

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

Examples:

  • "https://storage.googleapis.com/falserverless/model_tests/controlnet_sdxl/robot.jpeg"
pathstring

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"
image_encoder_pathstring

URL or the path to the image encoder weights.

Examples:

  • "h94/IP-Adapter"
image_encoder_subpathstring

Subpath to the image encoder weights.

Examples:

  • "models/image_encoder"
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

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

ControlNet

path*string

URL or the path to the control net weights.

Examples:

  • "diffusers/controlnet-canny-sdxl-1.0"
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"
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

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.

widthinteger

The width of the image in pixels.

heightinteger

The height of the image in pixels.

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>