Introduction

AI features for iOS and macOS apps, in plain Swift.

swift-ai-sdk is a toolkit for building AI features into iOS and macOS apps: streaming chat, agents that call your code, structured output, live voice, and Apple's on-device models, all behind one small API.

The whole thing in four lines:

import AI

let result = try await generateText(
  model: AnthropicModel("claude-sonnet-5"),
  prompt: "Why is the sky blue?"
)
print(result.text)

Swap AnthropicModel for OpenAIModel, GoogleModel, XaiModel, an Ollama model on your Mac, or Apple's on-device model. Nothing else changes.

If you've built with the AI SDK on the web, everything here will feel familiar, down to the streaming protocol: an app built with swift-ai-sdk can talk to the /api/chat route you already have.

Coming from the web?

You knowHere it's
generateText / streamTextThe same calls, with async/await and for try await
zod schemasA Schema DSL that validates output before decoding
useChatChatSession, an @Observable object your SwiftUI views watch
Server stream helpersUIMessageStream builders for Swift servers
RealtimeRealtimeSession for voice, same providers

And one thing the web can't do: on-device models answer without a network, a key, or your data leaving the phone.

Start here

Building with a coding agent? Install the swift-ai-sdk skill so it writes correct code. Every docs page is also raw markdown — append .mdx to any URL, or start from /llms.txt.