Fal.ai ⚡

Ultra-fast generative AI models for images, video, and more.

🎨

What you can do: Lightning-fast image generation (SDXL, FLUX), LoRA training, image-to-image, inpainting, face swap, virtual try-on, video generation, and more - all optimized for speed.

Setup

Add your Fal.ai API key in the ProtectMyAPI Dashboard.


Image Generation

FLUX Schnell (Fast)

let fal = ProtectMyAPI.falService()
 
let result = try await fal.generateFluxSchnell(
    prompt: "A majestic lion in a savanna at sunset, photorealistic",
    options: FalFluxOptions(
        imageSize: .landscape_16_9,
        numImages: 1,
        enableSafetyChecker: true
    )
)
 
for image in result.images {
    print("Image URL: \(image.url)")
    print("Size: \(image.width)x\(image.height)")
}

FLUX Pro (Higher Quality)

let result = try await fal.generateFluxPro(
    prompt: "Professional product photography of a luxury perfume bottle",
    options: FalFluxProOptions(
        imageSize: .square,
        numImages: 1,
        safetyTolerance: 2,
        guidanceScale: 3.5
    )
)

SDXL Generation

let result = try await fal.generateSDXL(
    prompt: "Cyberpunk city street at night, neon lights, rain, cinematic",
    negativePrompt: "blurry, low quality, distorted",
    options: FalSDXLOptions(
        imageSize: .landscape_16_9,
        numImages: 1,
        numInferenceSteps: 30,
        guidanceScale: 7.5,
        scheduler: .dpmPlusPlusSDE,
        seed: 42 // For reproducibility
    )
)

Image-to-Image

Transform existing images:

let result = try await fal.imageToImage(
    imageUrl: "https://example.com/photo.jpg",
    prompt: "Transform into anime style",
    options: FalImg2ImgOptions(
        strength: 0.75, // 0.0 = keep original, 1.0 = full transformation
        numInferenceSteps: 30,
        guidanceScale: 7.5
    )
)

Inpainting

Edit specific parts of an image:

let result = try await fal.inpaint(
    imageUrl: "https://example.com/photo.jpg",
    maskUrl: "https://example.com/mask.png", // White = edit, Black = keep
    prompt: "A red sports car",
    options: FalInpaintOptions(
        numInferenceSteps: 30,
        guidanceScale: 7.5
    )
)

LoRA Training

Train custom models on your images:

// Start LoRA training
let training = try await fal.trainLoRA(
    request: FalLoRATrainingRequest(
        imagesDataUrl: "https://example.com/training-images.zip",
        triggerWord: "mystyle", // Word to trigger your style
        steps: 1000,
        resolution: 512,
        learningRate: 0.0001,
        isStyle: true // true for style, false for subject
    )
)
 
print("Training ID: \(training.requestId)")
 
// Check training status
let status = try await fal.getTrainingStatus(requestId: training.requestId)
print("Status: \(status.status)")
 
// Use your trained LoRA
let result = try await fal.generateWithLoRA(
    prompt: "A portrait in mystyle",
    loraUrl: status.outputUrl!, // URL to trained LoRA weights
    loraScale: 0.8
)

Virtual Try-On

Try clothing on a person:

let result = try await fal.virtualTryOn(
    personImageUrl: "https://example.com/person.jpg",
    garmentImageUrl: "https://example.com/shirt.jpg",
    options: FalTryOnOptions(
        category: .upperBody, // upperBody, lowerBody, fullBody
        numImages: 1
    )
)
 
for image in result.images {
    print("Try-on result: \(image.url)")
}

Face Swap

let result = try await fal.faceSwap(
    sourceImageUrl: "https://example.com/face.jpg", // Face to use
    targetImageUrl: "https://example.com/target.jpg" // Image to swap into
)
 
print("Result: \(result.image.url)")

Upscaling

Enhance image resolution:

let result = try await fal.upscale(
    imageUrl: "https://example.com/low-res.jpg",
    options: FalUpscaleOptions(
        scale: 4, // 2x or 4x
        faceEnhance: true // Enhance faces
    )
)
 
print("Upscaled: \(result.image.url)")
print("New size: \(result.image.width)x\(result.image.height)")

Background Removal

let result = try await fal.removeBackground(
    imageUrl: "https://example.com/photo.jpg"
)
 
print("Transparent image: \(result.image.url)")

ControlNet

Guide generation with control images:

let result = try await fal.generateWithControlNet(
    prompt: "A futuristic city",
    controlImageUrl: "https://example.com/depth-map.png",
    controlType: .depth, // canny, depth, pose, etc.
    options: FalControlNetOptions(
        controlScale: 0.8,
        numInferenceSteps: 30
    )
)

Available Models

FLUX Models

ModelDescriptionSpeed
flux-schnellFast generation⚡ Ultra-fast
flux-devDevelopment qualityMedium
flux-proHighest qualitySlower
flux-pro-1.1Latest pro versionSlower

SDXL Models

ModelDescription
fast-sdxlOptimized SDXL
sdxl-lightning4-step SDXL
stable-cascadeWürstchen architecture

Utility Models

ModelDescription
rembgBackground removal
esrganImage upscaling
face-swapFace swapping
idt-vtonVirtual try-on

Image Sizes

SizeResolutionRatio
.square1024x10241:1
.squareHD1536x15361:1
.portrait_4_3896x11523:4
.portrait_16_9768x13449:16
.landscape_4_31152x8964:3
.landscape_16_91344x76816:9

Pricing

Fal.ai charges per request based on the model:

  • FLUX Schnell: ~$0.003/image
  • FLUX Pro: ~$0.05/image
  • SDXL: ~$0.01/image
  • LoRA Training: ~$0.50/1000 steps

Check their pricing page for current rates.