A Swift HTTP server that provides a REST interface to Apple's on-device Foundation Models (Apple Intelligence). Uses Hummingbird as the web framework.
- Swift 6.2 or newer
- macOS 26 or newer with Apple Intelligence available and enabled (compiler reports the Foundation Models APIs as macOS 26+)
swift buildProduction mode:
swift run FoundationAPIDebug mode:
swift run FoundationAPI --debugGET /healthReturns ok if the server is running and the model is available.
POST /generate
Content-Type: application/json
{ "prompt": "your text" }Returns JSON with both the input prompt and the model-generated response.
Example:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"prompt":"Write a haiku about Xcode"}' \
http://localhost:2929/generatePOST /v1/completions
Content-Type: application/json
{
"prompt": "your text",
"model": "auto",
"max_tokens": 256,
"temperature": 0.7,
"stream": false
}Returns OpenAI-compatible completion response format.
Example:
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"prompt": "Write a haiku about Xcode",
"model": "auto",
"max_tokens": 256,
"temperature": 0.7
}' \
http://localhost:2929/v1/completionsThe application supports runtime-configurable log levels:
- Normal mode (default): Only errors are displayed
- Debug mode: Includes detailed debug information about requests and model operations
Enable debug mode with the --debug flag when running:
swift run FoundationAPI --debugDebug logging is controlled at runtime, so you don't need to rebuild to toggle debug output.
- Runs an HTTP server on port 2929 using Hummingbird.
- Creates a
LanguageModelSessionwith concise instructions and temperature 0.7, maximum 256 response tokens. - Returns JSON with the input prompt and the model response.
- Checks model availability and reports clear errors if the on-device model is unavailable, not enabled, or still downloading.