Stability AI 🎨
Generate, edit, and enhance images with Stable Diffusion and Stable Image models.
🖼️
What you can do: Image generation (Ultra, Core, SD3.5), upscaling, inpainting, outpainting, background removal, style transfer, sketch-to-image, and video generation.
Setup
Add your Stability AI API key in the ProtectMyAPI Dashboard.
Image Generation
Stable Image Ultra (Highest Quality)
let stability = ProtectMyAPI.stabilityService()
let image = try await stability.generateUltra(
request: StabilityUltraRequest(
prompt: "A majestic castle on a cliff at sunset",
negativePrompt: "blurry, low quality, distorted",
aspectRatio: .landscape16x9,
seed: 12345
)
)
// Display the image
let uiImage = UIImage(data: image)Stable Image Core (Balanced)
let image = try await stability.generateCore(
request: StabilityCoreRequest(
prompt: "A cute robot playing chess",
stylePreset: .digitalArt,
aspectRatio: .square
)
)SD3.5 (Latest Model)
let image = try await stability.generateSD35(
request: StabilitySD35Request(
prompt: "Abstract geometric art with vibrant colors",
model: .sd35Large,
cfgScale: 7.0,
steps: 30
)
)Image Upscaling
Fast Upscale (4x)
let upscaled = try await stability.upscaleFast(
imageData: originalImage,
outputFormat: .png
)Conservative Upscale (Preserves Details)
let upscaled = try await stability.upscaleConservative(
imageData: originalImage,
prompt: "A detailed landscape photograph",
options: StabilityUpscaleOptions(
creativity: 0.3,
seed: 12345
)
)Image Editing
Search and Replace
let edited = try await stability.searchAndReplace(
imageData: originalImage,
searchPrompt: "cat",
prompt: "golden retriever dog"
)Remove Background
let transparent = try await stability.removeBackground(
imageData: productPhoto
)Inpainting (Fill Masked Area)
let inpainted = try await stability.inpaint(
imageData: originalImage,
maskData: maskImage, // White = area to fill
prompt: "A beautiful garden with flowers"
)Outpainting (Expand Image)
let expanded = try await stability.outpaint(
imageData: originalImage,
left: 200,
right: 200,
prompt: "Continue the landscape scenery"
)Control Generation
Sketch to Image
let image = try await stability.controlSketch(
imageData: sketchData,
prompt: "A detailed Victorian house with a garden",
controlStrength: 0.7
)Style Transfer
let stylized = try await stability.controlStyle(
imageData: contentImage,
styleImageData: styleImage,
prompt: "Apply the artistic style"
)Video Generation
Image to Video (Stable Video)
let video = try await stability.imageToVideo(
imageData: startImage,
seed: 12345,
cfgScale: 2.5,
motionBucketId: 127
)Available Models
| Model | Description | Best For |
|---|---|---|
| Ultra | Highest quality, photorealistic | Professional work |
| Core | Good quality, faster | General use |
| SD3.5 Large | Latest model, detailed | Complex scenes |
| SD3.5 Medium | Balanced speed/quality | Production |
| SD3.5 Turbo | Fastest | Prototyping |
Style Presets
enhance, anime, photographic, digital-art, comic-book, fantasy-art, line-art, analog-film, neon-punk, isometric, low-poly, origami, modeling-compound, cinematic, 3d-model, pixel-art, tile-texture
Aspect Ratios
| Ratio | Use Case |
|---|---|
1:1 | Social media, avatars |
16:9 | YouTube thumbnails, banners |
9:16 | Stories, TikTok |
4:3 | Traditional photos |
3:2 | DSLR standard |
21:9 | Ultrawide, cinematic |
Pricing Note
Stability AI charges per image generation. Check their pricing page for current rates. Ultra uses more credits than Core.