Skip to content

carledwards/apple-intelligence-foundation-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apple Intelligence Foundation Server (macOS)

A Swift command-line HTTP server that exposes the Apple Intelligence system language model over a simple JSON REST API using Apple's FoundationModels framework. Run it locally on supported devices to perform on-device language model inference.

This package is intended for experimentation and local development with Apple Intelligence.


Requirements

  • macOS 26.0+ (or iOS 26.0+, iPadOS 26.0+, visionOS 26.0+)
  • Swift 6.2+
  • Apple Intelligence enabled on your device
  • Xcode 17+ (for building)

Only devices that support Apple Intelligence can use this server. You must enable Apple Intelligence in System Settings.


Project Structure

apple-intelligence-foundation-server/
├── Package.swift              # Swift Package Manager configuration
├── Sources/
│   └── App/
│       └── main.swift         # Server implementation
└── README.md

Installation

  1. Clone or navigate to the project directory
  2. Resolve dependencies:
    swift package resolve

Usage

Running the server

swift run

The server will start on:

http://localhost:8080

API Overview

All responses are JSON. Errors are also returned as JSON with a consistent shape:

{
  "error": "Human-readable error message"
}

Endpoint summary

Method Path Description
POST /inference Run text generation via Apple Intelligence
GET /health Basic liveness/health check

API Endpoints

POST /inference

Send a prompt and receive a generated response from Apple Intelligence.

Request:

curl -X POST http://localhost:8080/inference \
  -H "Content-Type: application/json" \
  -d '{"prompt": "What is Swift programming?"}'

Request body:

{
  "prompt": "Your prompt text here"
}

Successful response:

{
  "response": "Generated text from Apple Intelligence..."
}

If the model is not available, you will receive an error response describing the issue.


GET /health

Health check endpoint to verify the server is running.

Request:

curl http://localhost:8080/health

Response:

{
  "status": "ok"
}

Implementation Details

  • Web framework: Vapor 4.89.0
  • AI integration: FoundationModels framework (Apple's on-device language model)
  • Architecture: Async/await with Actor-based inference service for concurrency safety
  • Port: 8080 (default Vapor HTTP port)
  • Context window: Up to 4,096 tokens per session (approximately 12,000-16,000 characters for English)

Model capabilities

The Apple Intelligence system language model excels at:

  • Text generation
  • Summarization
  • Entity extraction
  • Creative writing
  • Classification

Not suitable for: Basic math, code generation, complex logical reasoning


Best Practices

Performance tips

  • Keep prompts focused and specific
  • Limit prompt length for faster responses
  • Use phrases like "in three sentences" to get concise responses
  • Create a new session for each independent request
  • Stay within the 4,096 token context limit

Troubleshooting

Model not available

If you get "Model is unavailable" errors:

  1. Device not eligible
    Your device may not support Apple Intelligence. Check Apple's compatibility list.

  2. Apple Intelligence not enabled
    Go to System Settings → Apple Intelligence and enable it.

  3. Model not ready
    The model may still be downloading. Wait a few minutes and try again.

Build errors

If you encounter module import errors:

  1. Ensure you're running macOS 26.0+ or equivalent platform version
  2. Verify you're using Xcode 17+
  3. Re-resolve dependencies:
    swift package resolve
  4. If necessary, clean and rebuild:
    swift package clean
    swift build

References


License

This project is licensed under the MIT License.
See the LICENSE file for details.

About

Web server for Apple Intelligence Foundation Framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors