SwiftyAISwiftyAI

Search documentation

Find a docs page by title or section

1

Installation

SwiftyAI ships as a Swift Package. The package product is SwiftyAI, and the module import is also SwiftyAI.

Requirements

RequirementVersion
Swift tools5.9 or newer
iOS17 or newer
macOS14 or newer
Package productSwiftyAI
Module importimport 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.git

Add 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 SwiftyAI

First 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 installRead next
Need API keys and model stringsProvider setup
Want the first model callQuickstart
Building SwiftUI stateSwiftUI hooks
Adding custom providersCustom providers
Related docs

Continue with provider setup and quickstart.