A provider-agnostic Swift AI toolkit inspired by the Vercel AI SDK, offering a unified API for on-device and cloud AI models with tool calling, streaming, and SwiftUI integration.

Stars

38

7-day growth

No data

Forks

2

Open issues

0

License

MIT

Last updated

2026-07-21

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It bridges Apple's on-device Foundation Models and cloud providers like OpenAI/Anthropic under one Swift-native, Sendable-safe API, and directly speaks the Vercel UI message stream protocol, enabling reuse of existing Vercel AI SDK backends in iOS apps.

Who it is for

  • iOS/macOS developers building AI-powered apps
  • Teams already using Vercel AI SDK who want native Swift support
  • Developers needing on-device AI with fallback to cloud
  • Swift developers exploring structured output and agentic loops

Use cases

  • Build a chat interface that seamlessly switches between local offline models and cloud LLMs
  • Extract structured JSON from natural language using generateObject with native Swift Codable types
  • Create tool-using agents that perform multi-step reasoning and call external APIs
  • Implement voice-to-voice or realtime sessions with client-side tool execution

Strengths

  • Unified API across 20+ providers including Apple Foundation Models, OpenAI, Anthropic, and local Ollama
  • Full Swift 6 strict concurrency compliance with Sendable throughout and no @unchecked in public surface
  • Wire-level compatibility with Vercel AI SDK v5+ SSE protocol, allowing reuse of existing backend routes
  • Extensive test suite (376 unit tests) with wire-format goldens validated against the reference AI SDK

Considerations

  • Requires Swift 6 and Xcode 16+ (iOS 17+/macOS 14+ for @Observable chat session)
  • Currently at version 0.1 – some features may be experimental or have incomplete provider coverage
  • Limited to Apple platforms (iOS, macOS, etc.) due to Swift Package Manager and FoundationModels dependency

README quick start

swift-ai-sdk

Same code, on-device or cloud. swift-ai-sdk is a provider-agnostic AI toolkit for Swift, built on the Vercel AI SDK's design. You get generateText, streamText, and generateObject, tool calling with the agentic loop handled for you, a swappable transport layer that speaks Vercel's UI message stream protocol, and an @Observable chat session for SwiftUI. Swift 6 strict concurrency, Sendable throughout.

Why

On-device and cloud sit behind one API. FoundationModelsModel() is free, private, and works offline; AnthropicModel() and OpenAIModel() are a one-line swap away, and orFallback picks for you based on availability.

If you already run a Vercel AI SDK backend, your Swift app can use it as-is. HTTPChatTransport speaks the UI message stream protocol exactly (text-delta with a delta field, tool-input-delta with inputTextDelta, data: [DONE]), so the same /api/chat route that serves your React app serves your iOS app.

And it's Swift-6-native: everything is Sendable, streaming is AsyncThrowingStream, strict concurrency is on, and there's no @unchecked in the public surface.

The one abstraction

Every provider implements a single method:

protocol LanguageModel: Sendable {
    func stream(_ request: LanguageModelRequest) async throws -> AsyncThrowingStream
}

generateText, streamText, generateObject, and the chat transports are all just consumers of that stream. One code path, every backend.

Tour

Tools + the agentic loop

let weather = Tool(
    name: "weather",
    description: "Current weather for a city",
    parameters: ["type": "object", "properties": ["city": ["type": "string"]], "required": ["city"]]
) { args in
    ["tempC": 31, "city": args["city"] ?? .null]
}

let result = try await generateText(
    model: model,
    prompt: "Weather in Mumbai?",
    tools: [weather],
    stopWhen: [stepCountIs(4)],          // bound the loop (Vercel's stopWhen)
    prepareStep: { context in            // per-step overrides (model, messages, tools)
        context.stepNumber > 2 ? PrepareStepResult(model: cheaperModel) : nil
    }
)
result.text        // final answer, after the model called the tool
result.steps       // every round-trip: text, toolCalls, toolResults, usage

The loop streams too: streamText(...).fullStream yields step boundaries, tool calls, and to

Description

The AI SDK for your iOS and macOS Apps

Related repositories

Similar projects matched by category, topics, and programming language.

Blaizzy
Featured
Blaizzy GitHub avatar

nativ

Nativ is a native macOS app that lets you run AI models locally on Apple silicon, offering chat, model management, performance analytics, and an OpenAI/Anthropic-compatible API server.

AI & Machine LearningAI Vision & Audio
985
uzairansaruzi
Featured
uzairansaruzi GitHub avatar

hermex

Hermex is a native SwiftUI iPhone app that lets you control a self-hosted Hermes AI agent directly from your phone, with no subscriptions, tracking, or third-party relay.

AI & Machine LearningLarge Language Models
941
simonw
Featured
simonw GitHub avatar

speech-analyzer-cli

A macOS command-line tool that uses Apple's on-device speech APIs to transcribe prerecorded audio into plain text, JSON, JSONL, SRT, or WebVTT.

Developer ToolsCLI & Terminal
20