LanguageModelSession on any model
that conforms to its LanguageModel protocol. Apple’s open source
Foundation Models utilities
include ChatCompletionsLanguageModel, which talks to any chat completions
endpoint. Point it at EESI and the same session code runs on Nur: plain
answers, streaming, tool calling, guided generation and pictures.
It needs macOS, iOS, visionOS or watchOS 27, or Linux for server-side Swift.
Add the package
In Xcode, choose File › Add Package Dependencies and enterhttps://github.com/apple/foundation-models-utilities. In Package.swift:
.product(name: "FoundationModelsUtilities", package: "foundation-models-utilities")
to your target’s dependencies.
Ask Nur
/v1/chat/completions to the URL. Replies stream back
through the session as they are written, so streamResponse(to:) works too.
Guided generation
Ask for a Swift type and Nur answers with exactly that shape:Tools
Tools work the way they do with Apple’s own models. Nur decides when to call one, the session runs it, and Nur answers from what it returned:Keep the key safe
An API key in an app’s binary can be read by anyone who has the app. Ship it only in code you run yourself, such as server-side Swift, a command line tool or an internal app. For an app in people’s hands, keep the key on your server and have the app talk to your server, or seturl to your own server and add
the Authorization header there.
Pictures and errors
Nur sees pictures too: an image in the session’s transcript reaches her with the words. Errors come back as the session’s errors, with the API’s own message: a429 is too many requests or no credits left,
and the session can retry after a moment.