Amigo AIAmigo AI
Back to Docs

Amigo AI SDK API Reference

Complete API documentation for the AmigoFaceSwapSDK package.

AmigoFaceSwap

Static class. Main entry point for all SDK operations.

public final class AmigoFaceSwap {
    // Model Management
    static func downloadModelsIfNeeded(onProgress: ((Float) -> Void)?) async throws
    static func clearModelCache()

    // Initialization
    static func initialize(apiKey: String, onProgress: ((Float) -> Void)?) async throws

    // Face Enrollment
    static func enrollFace(from image: UIImage) async throws -> FaceLatent

    // Static Image Swap
    static func swapFace(in inputImage: UIImage, using latent: FaceLatent, lipMode: LipMode) async throws -> UIImage

    // Per-Frame API (synchronous)
    static func processFrame(_ pixelBuffer: CVPixelBuffer, using latent: FaceLatent, lipMode: LipMode) throws -> CIImage?
}

AmigoLiveCameraView (SwiftUI)

Drop-in SwiftUI view for live face-swapped camera feed.

public struct AmigoLiveCameraView: UIViewRepresentable {
    init(
        targetLatent: FaceLatent,
        lipMode: LipMode = .innerLips,
        cameraPosition: AVCaptureDevice.Position = .front,
        onFrame: ((UIImage) -> Void)? = nil
    )
}

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | targetLatent | FaceLatent | required | Enrolled face identity | | lipMode | LipMode | .innerLips | Lip blending control | | cameraPosition | AVCaptureDevice.Position | .front | Camera to use | | onFrame | ((UIImage) -> Void)? | nil | Callback for each processed frame |

AmigoLiveViewController (UIKit)

Ready-to-use UIViewController for live face swap.

public final class AmigoLiveViewController: UIViewController {
    init(targetLatent: FaceLatent, lipMode: LipMode = .innerLips, cameraPosition: AVCaptureDevice.Position = .front)
    let session: AmigoLiveSession
    var onFrame: ((UIImage) -> Void)?
}

AmigoLiveSession

Low-level live session for custom camera integrations.

public final class AmigoLiveSession: NSObject {
    let previewView: UIView
    var targetLatent: FaceLatent       // Change at runtime
    var lipMode: LipMode               // Default: .innerLips
    var isFaceSwapEnabled: Bool        // Default: true
    var backgroundImage: UIImage?      // nil to disable
    weak var delegate: AmigoLiveSessionDelegate?

    func start()
    func stop()
}

AmigoLiveSessionDelegate

public protocol AmigoLiveSessionDelegate: AnyObject {
    func session(_ session: AmigoLiveSession, didOutput frame: UIImage)
    func session(_ session: AmigoLiveSession, didEncounterError error: Error) // optional
}

FaceLatent

512-dimensional face embedding. Thread-safe value type.

public struct FaceLatent: Sendable, Hashable {
    init?(embedding: [Float])    // 512 Float32 values
    init?(embedding: [Double])   // Convenience for server responses
}

Obtained via AmigoFaceSwap.enrollFace(from:) or constructed from pre-computed embeddings. Cache and reuse — switch targets at runtime with zero latency.

LipMode

public enum LipMode: Int, Sendable {
    case none = 0        // Source face lips as-is
    case outerLips = 1   // Blend outer lip region
    case innerLips = 2   // Blend inner lips (default, most natural)
}

AmigoError

public enum AmigoError: LocalizedError {
    case notInitialized          // initialize() not called
    case invalidAPIKey(String)   // Key rejected
    case noFaceDetected          // No face in image/frame
    case modelLoadFailed         // CoreML model unavailable
    case inferenceFailure(String)
    case invalidInput(String)
    case modelDownloadFailed(String)
    case modelDecryptionFailed
    case networkRequired         // Models not cached, no network
}