A Swift-based web API that exposes Apple's on-device Foundation Models through an OpenAI-compatible HTTP interface. Built with Vapor and designed to run on Apple Intelligence-enabled devices.
- OpenAI-compatible: Works with existing OpenAI/OpenRouter client libraries
- Non-chat completions: Single-prompt responses
- Chat completions: Multi-turn conversations with context
- Streaming responses: Real-time token streaming via Server-Sent Events
- Multiple models: Base and permissive content guardrails
- Authentication
- Structured outputs
- Tool/function calling
- Tests
Requirements:
- Apple Intelligence-enabled device
- Swift 6.0+
Build the project:
swift buildRun the server:
swift run AppleIntelligenceApi serve [--hostname, -H] [--port, -p] [--bind, -b] [--unix-socket]The API will be available at http://localhost:8080 by default.
Port already in use:
lsof -i :8080 # Find out what's using the port
swift run AppleIntelligenceApi serve -p 9000 # Use a different port if neededApple Intelligence not available:
- Make sure it's enabled: Settings --> Apple Intelligence & Siri
- Check your device is supported
This API follows the same standard as OpenAI and OpenRouter, so it should be straightforward to adopt.
For completeness, here are some examples...
Chat completion:
curl http://localhost:8080/api/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "base",
"messages": [
{"role": "user", "content": "What is the capital of France?"}
]
}'Streaming Response:
curl http://localhost:8080/api/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "base",
"messages": [
{"role": "user", "content": "Tell me a story"}
],
"stream": true
}'from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8080/api/v1",
api_key="not-needed"
)
response = client.chat.completions.create(
model="base",
messages=[
{"role": "user", "content": "Hello!"}
]
)
print(response.choices[0].message.content)import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'http://localhost:8080/api/v1',
apiKey: 'not-needed'
});
const response = await client.chat.completions.create({
model: 'base',
messages: [{ role: 'user', content: 'Hello!' }],
stream: true
});
for await (const chunk of response) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}For a complete breakdown of how to use the API, I suggest looking at the OpenAI or OpenRouter documentation.
Our API differs in a few key places:
- Available models:
base(default guardrails) andpermissive(relaxed filtering) - Runs server on-device (so no API key needed)
- Not all features are available!
We currently do not have any tests! If you would like to implement some, please make a PR.
swift test./Sources/routes.swift: API route definition./Sources/Utils/AbortErrors.swift: Error type definitions./Sources/Utils/RequestContent.swift: Parsing incoming requests./Sources/Utils/ResponseSession.swift: Foundation models interface./Sources/Utils/ResponseGenerator.swift: Generates responses
Contributions are welcome! Please feel free to submit issues or pull requests.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a pull request
I currently do not plan to offer cloud inference for this API.
If you want to use the server on your local network, you can run the server from any Apple Intelligence-enabled device.
If you want cloud inference, you will probably want a VPS. Of course, this VPS needs to be on Apple Intelligence-enabled hardware; HostMyApple and MacInCloud seem reasonable.
- Built with Vapor web framework
- Uses Apple's Foundation Models Framework
- OpenAI-compatible API design based on OpenRouter
This is an unofficial API wrapper for Apple Intelligence. It is not affiliated with or endorsed by Apple Inc. Use responsibly and in accordance with Apple's terms of service.