Skip to content

DecartAI/decart-ios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Decart iOS SDK

Swift 5.9+ iOS 15.0+ License: MIT

Native Swift SDK for Decart AI - Real-time video processing and AI generation for iOS & macOS.

Overview

Decart iOS SDK provides two primary APIs:

  • RealtimeClient - Real-time video processing with WebRTC streaming
  • ProcessClient - Batch image and video generation

Both APIs leverage modern Swift concurrency (async/await) with type-safe interfaces and comprehensive error handling.

Features

  • âś… Real-time video processing with WebRTC
  • âś… Batch image and video generation
  • âś… Native Swift with modern concurrency (async/await)
  • âś… AsyncStream events for reactive state management
  • âś… Type-safe API with compile-time guarantees
  • âś… iOS 15+ and macOS 12+ support
  • âś… SwiftUI ready

Installation

Swift Package Manager

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/decartai/decart-ios.git", from: "0.0.4")
]

Or in Xcode:

  1. File → Add Package Dependencies
  2. Enter: https://github.com/decartai/decart-ios
  3. Select version and add to target

Usage Examples

1. Real-time Video Processing

Stream video with real-time AI processing using WebRTC:

import DecartSDK
import WebRTC

// Configure SDK
let config = DecartConfiguration(apiKey: "your-api-key")
let client = DecartClient(decartConfiguration: config)

// Create realtime client
let model = Models.realtime(.mirage)
let realtimeClient = try client.createRealtimeClient(
    options: RealtimeConfiguration(
        model: model,
        initialState: ModelState(prompt: Prompt(text: "Lego World"))
    )
)

// Capture local camera stream
let (localStream, cameraCapturer) = try await RealtimeCameraCapture.captureLocalCameraStream(
    realtimeClient: realtimeClient,
    cameraFacing: .front
)

// Connect and receive remote stream
let remoteStream = try await realtimeClient.connect(localStream: localStream)
remoteStream.videoTrack.add(videoRenderer)

// Listen to connection events
Task {
    for await state in realtimeClient.events {
        switch state {
        case .connected:
            print("Connected")
        case .disconnected:
            print("Disconnected")
        case .error:
            print("Connection error")
        default:
            break
        }
    }
}

// Update prompt in real-time
realtimeClient.setPrompt(Prompt(text: "Anime World"))

// Cleanup
defer {
    cameraCapturer.stopCapture(completionHandler: {})
    Task { await realtimeClient.disconnect() }
}

2. Text-to-Image Generation

Generate images from text prompts:

import DecartSDK

// Configure SDK
let config = DecartConfiguration(apiKey: "your-api-key")
let client = DecartClient(decartConfiguration: config)

// Create input
let input = TextToImageInput(prompt: "Retro robot in neon city")

// Create process client
let processClient = try client.createProcessClient(
    model: .lucy_pro_t2i,
    input: input
)

// Generate image
let imageData = try await processClient.process()
let image = UIImage(data: imageData)

3. Image-to-Video Generation

Generate videos from reference images:

import DecartSDK
import UniformTypeIdentifiers

// Configure SDK
let config = DecartConfiguration(apiKey: "your-api-key")
let client = DecartClient(decartConfiguration: config)

// Load reference image
let imageData = try Data(contentsOf: referenceImageURL)
let fileInput = try FileInput.from(data: imageData, uniformType: .jpeg)

// Create input
let input = ImageToVideoInput(prompt: "Make it dance", data: fileInput)

// Create process client
let processClient = try client.createProcessClient(
    model: .lucy_pro_i2v,
    input: input
)

// Generate video
let videoData = try await processClient.process()
try videoData.write(to: outputURL)

API Reference

Core Configuration

DecartConfiguration

Initialize the SDK with your API credentials:

let config = DecartConfiguration(
    baseURL: "https://api3.decart.ai", // Optional, defaults to api3.decart.ai
    apiKey: "your-api-key"
)

DecartClient

Main entry point for creating realtime and process clients:

let client = DecartClient(decartConfiguration: config)

RealtimeClient

Real-time video streaming with WebRTC.

Methods

func createRealtimeClient(options: RealtimeConfiguration) throws -> RealtimeClient
func connect(localStream: RealtimeMediaStream) async throws -> RealtimeMediaStream
func disconnect() async
func setPrompt(_ prompt: Prompt)

Events

let events: AsyncStream<DecartRealtimeConnectionState>

// States: .idle, .connecting, .connected, .disconnected, .error

Available Models

Models.realtime(.mirage)
Models.realtime(.mirage_v2)
Models.realtime(.lucy_v2v_720p_rt)

ProcessClient

Batch image and video generation.

Methods

func createProcessClient(model: ImageModel, input: TextToImageInput) throws -> ProcessClient
func createProcessClient(model: ImageModel, input: ImageToImageInput) throws -> ProcessClient
func createProcessClient(model: VideoModel, input: TextToVideoInput) throws -> ProcessClient
func createProcessClient(model: VideoModel, input: ImageToVideoInput) throws -> ProcessClient
func createProcessClient(model: VideoModel, input: VideoToVideoInput) throws -> ProcessClient

func process() async throws -> Data

Available Models

Image Models:

  • .lucy_pro_t2i - Text to image
  • .lucy_pro_i2i - Image to image

Video Models:

  • .lucy_pro_t2v - Text to video
  • .lucy_pro_i2v - Image to video
  • .lucy_pro_v2v - Video to video
  • .lucy_dev_i2v - Image to video (dev)
  • .lucy_dev_v2v - Video to video (dev)

Input Types

// Text-based inputs
TextToImageInput(prompt: String, seed: Int? = nil, resolution: ProResolution? = .res720p)
TextToVideoInput(prompt: String, seed: Int? = nil, resolution: ProResolution? = .res720p)

// File-based inputs
ImageToImageInput(prompt: String, data: FileInput, seed: Int? = nil)
ImageToVideoInput(prompt: String, data: FileInput, seed: Int? = nil)
VideoToVideoInput(prompt: String, data: FileInput, seed: Int? = nil)

// File input helpers
FileInput.image(data: Data, filename: String = "image.jpg")
FileInput.video(data: Data, filename: String = "video.mp4")
FileInput.from(data: Data, uniformType: UTType?)

Requirements

  • iOS 15.0+ / macOS 12.0+
  • Swift 5.9+
  • Xcode 15.0+

Architecture

The SDK follows Swift best practices:

  • Value types (structs) for configuration and data models
  • Reference types (classes) for connection management
  • AsyncStream for reactive event streams
  • async/await for asynchronous operations
  • Structured concurrency with Task-based cancellation
  • Type-safe protocols for proper Swift error handling

Dependencies

  • WebRTC - WebRTC framework for iOS/macOS

License

MIT License - see LICENSE for details.

Links