Stable Diffusion with LoRAs
fal-ai/lora
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.
Authentication guidelines
FAL_KEY
variable set in your environment. Make sure you check out our docs to find out more about our API and how to manage authentication, long-running requests and more.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"
variant
string
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_prompt
string
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)"
loras
list<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.
embeddings
list<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.
controlnets
list<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_mode
boolean
If set to true, the controlnet will be applied to only the conditional predictions.
ip_adapter
list<IPAdapter>
The IP adapter to use for the image generation.
image_encoder_path
string
The path to the image encoder model to use for the image generation.
Examples:
- "laion/CLIP-ViT-H-14-laion2B-s32B-b79K"
image_encoder_subfolder
string
The subfolder of the image encoder model to use for the image generation.
Examples:
image_encoder_weight_name
string
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_url
string
The URL of the IC Light model to use for the image generation.
ic_light_image_url
string
The URL of the IC Light model image to use for the image generation.
seed
integer
The same seed and the same prompt given to the same version of Stable Diffusion will output the same image every time.
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_steps
integer
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_scale
float
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_skip
integer
Skips part of the image generation process, leading to slightly different results. This means the image renders faster, too.
scheduler
SchedulerEnum
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_format
ImageFormatEnum
The format of the generated image. Default value: "png"
Possible values: "jpeg", "png"
num_images
integer
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_checker
boolean
If set to true, the safety checker will be enabled.
tile_width
integer
The size of the tiles to be used for the image generation. Default value: 4096
tile_height
integer
The size of the tiles to be used for the image generation. Default value: 4096
tile_stride_width
integer
The stride of the tiles to be used for the image generation. Default value: 2048
tile_stride_height
integer
The stride of the tiles to be used for the image generation. Default value: 2048
debug_latents
boolean
If set to true, the latents will be saved for debugging.
debug_per_pass_latents
boolean
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_latents
File
The latents saved for debugging.
debug_per_pass_latents
File
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.
HTTPValidationError
detail
list<ValidationError>
Types
IPAdapter
ip_adapter_image_url*
string | list<string>
URL of the image to be used as the IP adapter.
ip_adapter_mask_url
string
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_subfolder
string
Subfolder in the model directory where the IP adapter weights are stored.
Examples:
- "sdxl_models"
weight_name
string
Name of the weight file.
Examples:
- "ip-adapter-plus_sdxl_vit-h.safetensors"
insight_face_model_path
string
URL or the path to the InsightFace model weights.
scale
float
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_json
Scale 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_factor
float
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_type
string
The mime type of the file.
Examples:
- "image/png"
file_name
string
The name of the file. It will be auto-generated if not provided.
Examples:
- "z9RV14K95DvU.png"
file_size
integer
The size of the file in bytes.
file_data
string
File data
ImageSize
width
integer
The width of the generated image. Default value: 512
height
integer
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"
scale
float
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"
tokens
list<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_type
string
The mime type of the file.
Examples:
- "image/png"
file_name
string
The name of the file. It will be auto-generated if not provided.
Examples:
- "z9RV14K95DvU.png"
file_size
integer
The size of the file in bytes.
file_data
string
File data
width
integer
The width of the image in pixels.
height
integer
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"
variant
string
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_url
string
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_scale
float
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_percentage
float
The percentage of the image to start applying the controlnet in terms of the total timesteps.
end_percentage
float
The percentage of the image to end applying the controlnet in terms of the total timesteps. Default value: 1
ip_adapter_index
integer
The index of the IP adapter to be applied to the controlnet. This is only needed for InstantID ControlNets.