Intermediate20 minModule 1 of 3

Setup & First Prediction

Install the Skytells Swift SDK, configure your API key, and generate your first AI image — all in under 10 minutes.

Installation

The SDK is distributed as a Swift Package with zero external dependencies — it uses only Foundation and Swift concurrency.

  1. Open your project in Xcode
  2. Go to File → Add Package Dependencies…
  3. Paste the URL:
    https://github.com/skytells/swift-sdk.git
  4. Set the version rule to Up to Next Major Version from 1.0.0
  5. Click Add Package

Swift Package Manager (CLI)

Add to your Package.swift:

// Package.swift
dependencies: [
    .package(url: "https://github.com/skytells/swift-sdk.git", from: "1.0.0"),
],
targets: [
    .target(
        name: "YourTarget",
        dependencies: [.product(name: "Skytells", package: "swift-sdk")]
    ),
]

Storing your API key

Never hard-code API keys in Swift source files. The standard approaches:

iOS/macOS: .xcconfig + Info.plist

Create a Config.xcconfig file (excluded from version control):

SKYTELLS_API_KEY = sk-your-api-key-here

Add to Info.plist:

<key>SkytellsAPIKey</key>
<string>$(SKYTELLS_API_KEY)</string>

Read at runtime:

let apiKey = Bundle.main.infoDictionary?["SkytellsAPIKey"] as? String ?? ""

Xcode Scheme Environment Variables (development only)

In Xcode: Edit Scheme → Run → Arguments → Environment Variables
Add SKYTELLS_API_KEY = sk-your-key

let apiKey = ProcessInfo.processInfo.environment["SKYTELLS_API_KEY"] ?? ""

Your first prediction

import Skytells

let client = SkytellsClient(apiKey: "sk-your-api-key")

let prediction = try await client.predictions.create(
    model: "truefusion-pro",
    input: [
        "prompt": "A photorealistic mountain lake at sunrise, 4K",
        "width": 1024,
        "height": 1024,
    ]
)

if prediction.status == .succeeded, let outputURLs = prediction.output {
    print("Image URL:", outputURLs.first ?? "")
}

The SDK automatically waits for the prediction to complete — no manual polling needed for the default case.

Client configuration

let client = SkytellsClient(
    apiKey: "sk-your-api-key",
    baseURL: URL(string: "https://api.skytells.ai/v1")!, // default
    timeout: 120,     // seconds
    maxRetries: 3     // automatic retry on server errors
)

Verifying installation

A quick test you can run from a Swift playground or unit test:

import Skytells
import XCTest

class SkytellsSetupTest: XCTestCase {
    func testListModels() async throws {
        let client = SkytellsClient(
            apiKey: ProcessInfo.processInfo.environment["SKYTELLS_API_KEY"]!
        )
        let models = try await client.models.list()
        XCTAssertFalse(models.isEmpty, "Expected at least one model")
        print("Available models:", models.map(\.id))
    }
}

Summary

  • Install via Xcode Package Dependencies or Package.swift
  • Store API keys in .xcconfig or scheme environment variables — never in source
  • SkytellsClient.predictions.create() handles auth, request, and polling automatically
  • The SDK requires iOS 15+, macOS 12+, Swift 5.9+

On this page