How Do You Call the Mac's Built-in Apple Intelligence Model from .NET? A developer building an Avalonia Markdown editor connected Apple's on-device Foundation Models language model to a plain .NET 10 app by writing a Swift bridge exposed through @_cdecl and called via P/Invoke, since the Swift-only framework has no Objective-C or C interface. The bridge exposes functions to check status, read the context size, start and cancel generation, and release resources, passing requests as JSON with text and status returned through callbacks. The work was packaged as the open-source Polhem.AI.Apple library, and the developer notes the model's 8,192-token context and schema limitations apply regardless of integration path. An on-device model with only a Swift API and a short context: how I connected it to IChatClient, and the trade-offs This post is based on macOS 27.2, Xcode 27.2 and .NET 10. Since macOS 26, a Mac with Apple Intelligence has a built-in on-device language model, which the Foundation Models framework makes available to apps. It runs locally: no API key, no server, no charge per use, and the data never leaves the computer. I am building a Markdown editor, and its AI features used to require users to enter their own API key or set up a local model. For someone who only wants AI to summarize a passage, that is a real hurdle, so I tried letting a .NET program use this built-in model directly. This post covers how I connected it, the problems I ran into along the way, and what the model is actually good for. The Foundation Models framework gives you the on-device model behind Apple Intelligence. To use it, all of these must hold: It is a small model with a small context the amount of text the model can take in at once, input and output together . My Mac on macOS 27.2 reports 8,192 tokens. Most of what it can and cannot do follows from that size. The value may change between system versions, so query it with the framework's contextSize in code rather than hard-coding it. One more thing to know up front: .NET calls native code through C functions P/Invoke or through Objective-C the bindings on Apple platforms, since most Apple frameworks have an Objective-C interface . Foundation Models, though, is a new Swift-only framework with no Objective-C interface, and it relies heavily on Swift's async, generics and macros, none of which have a C equivalent. Neither path connects, so the only option is to add a Swift adapter layer of your own in between. At the time of writing, I found roughly three approaches: Use Microsoft's Microsoft.Maui.Essentials.AI. It provides an IChatClient for this model, with more features image support, for example . However, its Apple client only exists for platform-specific target frameworks such as net11.0-ios , net11.0-maccatalyst and net11.0-macos , and it is still in preview. If your app is already MAUI or built for those target frameworks, this is the easiest choice. Go through a local HTTP service. Some community tools wrap the model as an OpenAI-compatible API, so the .NET side calls it like any OpenAI service. The upside is that you never touch native code; the downside is that users have to install and start a separate program. Write your own Swift bridge and call it with P/Invoke. You write a small dynamic library in Swift that exposes only C functions, and .NET calls it with LibraryImport . An ordinary net10.0 program a console app, an Avalonia desktop app can use it, with no change of target framework and no extra service. My editor is an Avalonia app built for plain net10.0 , and the same code has to run on Windows and Linux, so switching to a platform-specific target framework does not pay off. Asking users to install a service brings back the very hurdle I wanted to remove. So I took the third path, and later turned this layer into an open-source package, Polhem.AI.Apple. Most of what follows only comes up on this path, but the model's own limits and the schema problems apply whichever path you take. Swift can export a function with the C calling convention through @ cdecl . The whole bridge exposes only a few functions: check the status, get the context size, start a generation, cancel, and release. A generation request goes over as JSON, and text and the final status come back through callbacks: public typealias TextCallback = @convention c UnsafeMutableRawPointer?, UnsafePointer