Swift client library

Replicate now has a client library for Swift. It’s got everything you need to build an AI-powered app for iOS and macOS using Replicate’s HTTP API.

Add it as a package dependency to your project:

let package = Package(
    // name, platforms, products, etc.
    dependencies: [
        // other dependencies
        .package(url: "https://github.com/replicate/replicate-swift", from: "0.12.1"),
    ],
    targets: [
        .target(name: "<target>", dependencies: [
            // other dependencies
            .product(name: "Replicate", package: "replicate-swift"),
        ]),
        // other targets
    ]
)

Then, you can run predictions:

import Replicate

// Get your API token at https://replicate.com/account
private let replicate = Replicate.Client(token: <#token#>)

let output = try await replicate.run(
    "stability-ai/stable-diffusion:db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf",
    ["prompt": "a 19th century portrait of a wombat gentleman"]
)

print(output)
// ["https://replicate.com/api/models/stability-ai/stable-diffusion/files/50fcac81-865d-499e-81ac-49de0cb79264/out-0.png"]

Follow our guide to building a SwiftUI app or read the full documentation on GitHub.