{"by":"mi12-root","descendants":24,"id":45052200,"kids":[45056982,45057456,45058876,45058136,45057381,45058211],"score":74,"text":"We built SwiftAI, an open-source Swift library that lets you use Apple’s on-device LLMs when available (Apple opened access in June), and fall back to a cloud model when they aren’t available — all without duplicating code.<p>SwiftAI gives you:\n- A single, model-agnostic API\n- An agent&#x2F;tool loop\n- Strongly-typed structured outputs\n- Optional chat state<p>Backstory: We started experimenting with Apple’s local models because they’re free (no API calls), private, and work offline. The problem: not all devices support them (older iPhones, Apple Intelligence disabled, low battery, etc.). That meant writing two codepaths — one for local, one for cloud — and scattering branching logic across the app. SwiftAI centralizes that decision. Your feature code stays the same whether you’re on-device or cloud.<p>Example<p><pre><code>  import SwiftAI\n   \n  let llm: any LLM = SystemLLM.ifAvailable ?? OpenaiLLM(model: &quot;gpt-5-mini&quot;, apiKey: &quot;&lt;key&gt;&quot;)\n\n  let response = try await llm.reply(to: &quot;Write a haiku about Hacker News&quot;)\n  print(response.content)\n</code></pre>\nIt&#x27;s open source — we&#x27;d love for you to try it, break it, and help shape the roadmap. Join our discord &#x2F; slack or email us at root@mit12.dev.<p>Links<p>- GitHub (source, docs): <a href=\"https:&#x2F;&#x2F;github.com&#x2F;mi12labs&#x2F;SwiftAI\" rel=\"nofollow\">https:&#x2F;&#x2F;github.com&#x2F;mi12labs&#x2F;SwiftAI</a><p>- System Design: <a href=\"https:&#x2F;&#x2F;github.com&#x2F;mi12labs&#x2F;SwiftAI&#x2F;blob&#x2F;main&#x2F;Docs&#x2F;Proposals&#x2F;001-llm-api.md\" rel=\"nofollow\">https:&#x2F;&#x2F;github.com&#x2F;mi12labs&#x2F;SwiftAI&#x2F;blob&#x2F;main&#x2F;Docs&#x2F;Proposals...</a><p>- Swift Package Index (compat&#x2F;builds): <a href=\"https:&#x2F;&#x2F;swiftpackageindex.com&#x2F;mi12labs&#x2F;SwiftAI\" rel=\"nofollow\">https:&#x2F;&#x2F;swiftpackageindex.com&#x2F;mi12labs&#x2F;SwiftAI</a><p>- Discord <a href=\"https:&#x2F;&#x2F;discord.com&#x2F;invite&#x2F;ckfVGE5r\" rel=\"nofollow\">https:&#x2F;&#x2F;discord.com&#x2F;invite&#x2F;ckfVGE5r</a> and slack <a href=\"https:&#x2F;&#x2F;mi12swiftai.slack.com&#x2F;join&#x2F;shared_invite&#x2F;zt-3c3lr6dat-jJ8BHBsdWc47o4FDu2CgHQ#&#x2F;shared-invite&#x2F;email\" rel=\"nofollow\">https:&#x2F;&#x2F;mi12swiftai.slack.com&#x2F;join&#x2F;shared_invite&#x2F;zt-3c3lr6da...</a>","time":1756389111,"title":"Show HN: SwiftAI – open-source library to easily build LLM features on iOS/macOS","type":"story","url":"https://github.com/mi12labs/SwiftAI"}