Prodia
This page adapts the original AI SDK documentation: Prodia.
Prodia is a fast inference platform for generative AI, offering high-speed image generation with FLUX and Stable Diffusion models.
The Prodia provider is available in the ProdiaProvider module. Add it to your Swift package:
// Package.swift (excerpt)dependencies: [ .package(url: "https://github.com/teunlao/swift-ai-sdk", from: "0.14.1")],targets: [ .target( name: "YourTarget", dependencies: [ .product(name: "SwiftAISDK", package: "swift-ai-sdk"), .product(name: "ProdiaProvider", package: "swift-ai-sdk") ] )]Provider Instance
Section titled “Provider Instance”You can import the default provider instance prodia:
import SwiftAISDKimport ProdiaProvider
let model = prodia.image("inference.flux-fast.schnell.txt2img.v2")If you need a customized setup, use createProdia and create a provider instance with your settings:
import ProdiaProvider
let prodia = createProdia(settings: ProdiaProviderSettings( apiKey: ProcessInfo.processInfo.environment["PRODIA_TOKEN"], baseURL: "https://inference.prodia.com/v2", headers: ["X-Custom-Header": "value"]))You can use the following optional settings to customize the Prodia provider instance:
-
baseURL
StringUse a different URL prefix for API calls. The default prefix is
https://inference.prodia.com/v2. -
apiKey
StringAPI key that is being sent using the
Authorizationheader as a Bearer token. It defaults to thePRODIA_TOKENenvironment variable. -
headers
[String: String]Custom headers to include in the requests.
-
fetch
FetchFunctionCustom fetch implementation (middleware) for testing or request interception.
Image Models
Section titled “Image Models”You can create Prodia image models using the .image() factory method.
For more on image generation with the Swift AI SDK see Image Generation.
Basic Usage
Section titled “Basic Usage”import SwiftAISDKimport ProdiaProvider
let result = try await generateImage( model: prodia.image("inference.flux-fast.schnell.txt2img.v2"), prompt: "A cat wearing an intricate robe")
try result.image.data.write(to: URL(fileURLWithPath: "image.png"))Model Capabilities
Section titled “Model Capabilities”Prodia offers fast inference for various image generation models. Here are the supported model types:
| Model | Description |
|---|---|
inference.flux-fast.schnell.txt2img.v2 | Fast FLUX Schnell model for text-to-image generation |
inference.flux.schnell.txt2img.v2 | FLUX Schnell model for text-to-image generation |
Note: Prodia supports additional model IDs. Check the Prodia documentation for the full list of available models.
Image Size
Section titled “Image Size”You can specify the image size using the size parameter in WIDTHxHEIGHT format:
let result = try await generateImage( model: prodia.image("inference.flux-fast.schnell.txt2img.v2"), prompt: "A serene mountain landscape at sunset", size: "1024x768")Provider Options
Section titled “Provider Options”Prodia image models support additional options through the providerOptions.prodia object:
let result = try await generateImage( model: prodia.image("inference.flux-fast.schnell.txt2img.v2"), prompt: "A cat wearing an intricate robe", providerOptions: [ "prodia": [ "width": 1024, "height": 768, "steps": 4, "stylePreset": "cinematic" ] ])The following provider options are supported:
- width number - Output width in pixels (256–1920). When set, this overrides any width derived from
size. - height number - Output height in pixels (256–1920). When set, this overrides any height derived from
size. - steps number - Number of computational iterations (1–4). More steps typically produce higher quality results.
- stylePreset string - Apply a visual theme to the output image. Supported presets:
3d-model,analog-film,anime,cinematic,comic-book,digital-art,enhance,fantasy-art,isometric,line-art,low-poly,neon-punk,origami,photographic,pixel-art,texture,craft-clay. - loras string[] - Augment the output with up to 3 LoRA models.
- progressive boolean - When using JPEG output, return a progressive JPEG.
You can use the seed parameter to get reproducible results:
let result = try await generateImage( model: prodia.image("inference.flux-fast.schnell.txt2img.v2"), prompt: "A serene mountain landscape at sunset", seed: 12345)Provider Metadata
Section titled “Provider Metadata”The generateImage response includes provider-specific metadata in providerMetadata["prodia"]?.images[]. Each image object may contain the following properties:
- jobId string - The unique identifier for the generation job.
- seed number - The seed used for generation. Useful for reproducing results.
- elapsed number - Generation time in seconds.
- iterationsPerSecond number - Processing speed metric.
- createdAt string - Timestamp when the job was created.
- updatedAt string - Timestamp when the job was last updated.
import SwiftAISDKimport ProdiaProvider
let result = try await generateImage( model: prodia.image("inference.flux-fast.schnell.txt2img.v2"), prompt: "A serene mountain landscape at sunset")
if let first = result.providerMetadata["prodia"]?.images.first, case let .object(fields) = first, case let .string(jobId)? = fields["jobId"] { print("Job ID:", jobId)}