Installation
SwiftyAI ships as a Swift Package. The package product is SwiftyAI, and the module import is also SwiftyAI.
Requirements
| Requirement | Version |
|---|---|
| Swift tools | 5.9 or newer |
| iOS | 17 or newer |
| macOS | 14 or newer |
| Package product | SwiftyAI |
| Module import | import SwiftyAI |
The package itself does not force a UI framework. You can use the core generation APIs in app targets, command-line tools, and tests.
Xcode Package Dependency
In Xcode, open your project, add a package dependency, and use:
https://github.com/Kartikayy007/SwiftyAI.gitAdd the SwiftyAI product to the target that will make SDK calls.
Swift Package Manifest
For a SwiftPM app or library, add SwiftyAI to Package.swift:
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "MyApp",
platforms: [
.iOS(.v17),
.macOS(.v14)
],
dependencies: [
.package(url: "https://github.com/Kartikayy007/SwiftyAI.git", branch: "main")
],
targets: [
.target(
name: "MyApp",
dependencies: ["SwiftyAI"]
)
]
)Then import the module where you call the SDK:
import SwiftyAIFirst Compile Check
This small snippet only constructs a provider. It does not make a network request until generateText, streamText, or another SDK function is called.
import SwiftyAI
let model = OpenAICompatibleProvider(
baseURL: "https://api.openai.com/v1",
apiKey: ProcessInfo.processInfo.environment["OPENAI_API_KEY"] ?? "",
model: "gpt-4o-mini"
)Keep API keys out of source control. In app targets, read them from secure app configuration. In local experiments, environment variables are fine.
| After install | Read next |
|---|---|
| Need API keys and model strings | Provider setup |
| Want the first model call | Quickstart |
| Building SwiftUI state | SwiftUI hooks |
| Adding custom providers | Custom providers |