AI SDK
Put AI in your app
by tonight.
Streaming chat, agents that call your code, live voice, and models that run on the phone itself. One package for iOS and macOS.
import AI
let result = streamText(
model: AnthropicModel("claude-sonnet-5"),
prompt: "Weather in Mumbai?",
tools: [weatherTool],
reasoning: .medium
)
for try await token in result.textStream {
print(token, terminator: "")
}Everything you need.
Nothing to glue together.
Any model. One line to change your mind.
Claude, GPT, Gemini, Grok, or Ollama running on your Mac. Pick one today, swap it tomorrow, and nothing else in your code moves.
Works in airplane mode.
Apple's on-device models answer through the same call as the cloud ones. No network, no key, no data leaving the phone.
JSON you can actually trust.
Describe the shape, get typed Codable values back. Bad output turns into a thrown error, not a crash in your view code.
Schema.object([
"name": .string(),
"pop": .integer()
])A chat screen in an afternoon.
ChatSession holds the messages, streams the tokens, and talks to the same route your web app already uses. SwiftUI renders it.
@State var chat = ChatSession(
transport: HTTPChatTransport(
api: chatRoute
)
)
ForEach(chat.messages) {
Text($0.text)
}Talk to it. It talks back.
Live voice over WebSockets: the mic goes in, speech comes out, and your tools run in between. Interrupt it mid-sentence and it stops.
Your backend won't
notice the difference.
The app speaks the same streaming protocol your web frontend does, chunk for chunk. Keep the server you have. Add the app you've been meaning to build.
Read About the ProtocolOnly on iOS and macOS
The model is already
in their pocket.
Apple Intelligence answers on the device itself: free, instant, and private. When it isn't available, fall back to the cloud with one line. Your feature code never knows which one ran.
let model: any LanguageModel =
available ? FoundationModelsModel()
: AnthropicModel("claude-sonnet-5")Ship it.
Add the package, pick a model, send a message. If Ollama is running on your Mac, you don't even need an API key.
Open source, MIT licensed.
Building with an agent? Every docs page is raw markdown at /llms.txt.
