{"id":28794135,"url":"https://github.com/meridius-labs/apple-on-device-ai","last_synced_at":"2026-04-28T17:03:24.526Z","repository":{"id":299724867,"uuid":"1004001506","full_name":"Meridius-Labs/apple-on-device-ai","owner":"Meridius-Labs","description":"Apple foundation model bindings for NodeJS (supports Vercel AI)","archived":false,"fork":false,"pushed_at":"2025-06-18T01:37:46.000Z","size":0,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-18T01:42:22.648Z","etag":null,"topics":["ai","apple","foundation","llm","macos","macos26","model","tahoe","vercelaisdk"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Meridius-Labs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-18T01:10:19.000Z","updated_at":"2025-06-18T01:37:43.000Z","dependencies_parsed_at":"2025-06-18T01:42:30.556Z","dependency_job_id":"87b0da1a-5a4d-4c92-9012-314ed5ad55c6","html_url":"https://github.com/Meridius-Labs/apple-on-device-ai","commit_stats":null,"previous_names":["meridius-labs/apple-on-device-ai"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Meridius-Labs/apple-on-device-ai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meridius-Labs%2Fapple-on-device-ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meridius-Labs%2Fapple-on-device-ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meridius-Labs%2Fapple-on-device-ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meridius-Labs%2Fapple-on-device-ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Meridius-Labs","download_url":"https://codeload.github.com/Meridius-Labs/apple-on-device-ai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meridius-Labs%2Fapple-on-device-ai/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260471627,"owners_count":23014254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","apple","foundation","llm","macos","macos26","model","tahoe","vercelaisdk"],"created_at":"2025-06-18T02:04:46.974Z","updated_at":"2026-04-28T17:03:24.521Z","avatar_url":"https://github.com/Meridius-Labs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [Unofficial] Apple Foundation Models bindings for Bun/NodeJS\n\n## 🔥 Supports [Vercel AI SDK](https://ai-sdk.dev/)\n\n## Features\n\n- 🍎 **Apple Intelligence Integration**: Direct access to Apple's on-device models\n- 🧠 **Dual API Support**: Use either the native Apple AI interface or Vercel AI SDK\n- 🌊 **Streaming Support**: Real-time response streaming with OpenAI-compatible chunks\n- 🎯 **Object Generation**: Structured data generation with Zod schemas or JSON Schema\n- 💬 **Chat Interface**: OpenAI-style chat completions with message history\n- 🔧 **Tool Calling**: Function/tool calling with Zod or JSON Schema\n- 🔄 **Cross-Platform**: Works with React, Next.js, Vue, Svelte, and Node.js (Apple Silicon)\n- 📝 **TypeScript**: Full type safety and excellent DX\n\n## Installation\n\n```bash\n# Using bun (recommended)\nbun add @meridius-labs/apple-on-device-ai\n\n# If you don't have these already\nbun add ai zod\n```\n\n## Quick Start\n\n### Native Apple AI Interface\n\n```typescript\nimport { chat } from \"@meridius-labs/apple-on-device-ai\";\n\n// Simple text generation\nconst response = await chat({ messages: \"What is the capital of France?\" });\nconsole.log(response.text); // \"Paris is the capital of France.\"\n\n// Chat with message history\nconst chatResponse = await chat({\n  messages: [\n    { role: \"system\", content: \"You are a helpful assistant.\" },\n    { role: \"user\", content: \"Hello!\" },\n  ],\n});\nconsole.log(chatResponse.text);\n\n// Streaming responses\nfor await (const chunk of chat({ messages: \"Tell me a story\", stream: true })) {\n  process.stdout.write(chunk);\n}\n\n// Structured object generation (Zod)\nimport { z } from \"zod\";\nconst UserSchema = z.object({\n  name: z.string(),\n  age: z.number(),\n});\nconst structured = await chat({\n  messages: \"Generate a user object\",\n  schema: UserSchema,\n});\nconsole.log(structured.object); // { name: \"Alice\", age: 30 }\n\n// Tool calling\nconst mathTool = {\n  name: \"calculator\",\n  description: \"Performs basic math operations\",\n  jsonSchema: {\n    type: \"object\",\n    properties: {\n      operation: {\n        type: \"string\",\n        enum: [\"add\", \"subtract\", \"multiply\", \"divide\"],\n      },\n      a: { type: \"number\" },\n      b: { type: \"number\" },\n    },\n    required: [\"operation\", \"a\", \"b\"],\n  },\n  handler: async ({ operation, a, b }) =\u003e {\n    switch (operation) {\n      case \"add\":\n        return { result: a + b };\n      case \"subtract\":\n        return { result: a - b };\n      case \"multiply\":\n        return { result: a * b };\n      case \"divide\":\n        return { result: a / b };\n    }\n  },\n};\nconst withTools = await chat({\n  messages: \"What is 25 times 4?\",\n  tools: [mathTool],\n});\nconsole.log(withTools.toolCalls); // [{ function: { name: \"calculator\" }, ... }]\n```\n\n### Vercel AI SDK Integration\n\n```typescript\nimport { appleAI } from \"@meridius-labs/apple-on-device-ai\";\nimport { generateText, streamText, generateObject } from \"ai\";\nimport { z } from \"zod\";\n\n// Text generation\nconst { text } = await generateText({\n  model: appleAI(),\n  messages: [{ role: \"user\", content: \"Explain quantum computing\" }],\n});\nconsole.log(text);\n\n// Streaming\nconst { textStream } = await streamText({\n  model: appleAI(),\n  messages: [{ role: \"user\", content: \"Write a poem about technology\" }],\n});\nfor await (const delta of textStream) {\n  process.stdout.write(delta);\n}\n\n// Structured object generation\nconst { object } = await generateObject({\n  model: appleAI(),\n  prompt: \"Generate a chocolate chip cookie recipe\",\n  schema: z.object({\n    recipe: z.object({\n      name: z.string(),\n      ingredients: z.array(z.string()),\n      steps: z.array(z.string()),\n    }),\n  }),\n});\nconsole.log(object);\n\n// Tool calling\nconst { text, toolCalls } = await generateText({\n  model: appleAI(),\n  messages: [{ role: \"user\", content: \"What's the weather in Tokyo?\" }],\n  tools: {\n    weather: {\n      description: \"Get weather information\",\n      parameters: z.object({ location: z.string() }),\n      execute: async ({ location }) =\u003e ({\n        temperature: 72,\n        condition: \"sunny\",\n        location,\n      }),\n    },\n  },\n});\nconsole.log(toolCalls);\n```\n\n### Tool Calling \u0026 Structured Generation with Vercel AI SDK\n\n#### Tool Calling Example\n\nYou can define tools using the `tool` helper and provide an `inputSchema` (Zod) and an `execute` function. The model will call your tool when appropriate, and you can handle tool calls and streaming output as follows:\n\n```typescript\nimport { appleAI } from \"@meridius-labs/apple-on-device-ai\";\nimport { streamText, tool } from \"ai\";\nimport { z } from \"zod\";\n\nconst result = streamText({\n  model: appleAI(),\n  messages: [{ role: \"user\", content: \"What's the weather in Tokyo?\" }],\n  tools: {\n    weather: tool({\n      description: \"Get weather information\",\n      inputSchema: z.object({ location: z.string() }),\n      execute: async ({ location }) =\u003e ({\n        temperature: 72,\n        condition: \"sunny\",\n        location,\n      }),\n    }),\n  },\n});\n\nfor await (const delta of result.fullStream) {\n  if (delta.type === \"text\") {\n    process.stdout.write(delta.text);\n  } else if (delta.type === \"tool-call\") {\n    console.log(`\\n🔧 Tool call: ${delta.toolName}`);\n    console.log(`   Arguments: ${JSON.stringify(delta.input)}`);\n  } else if (delta.type === \"tool-result\") {\n    console.log(`✅ Tool result: ${JSON.stringify(delta.output)}`);\n  }\n}\n```\n\n#### Structured/Object Generation Example\n\nYou can generate structured objects directly from the model using Zod schemas:\n\n```typescript\nimport { appleAI } from \"@meridius-labs/apple-on-device-ai\";\nimport { generateObject } from \"ai\";\nimport { z } from \"zod\";\n\nconst { object } = await generateObject({\n  model: appleAI(),\n  prompt: \"Generate a user profile\",\n  schema: z.object({\n    name: z.string(),\n    age: z.number(),\n    email: z.string().email(),\n  }),\n});\nconsole.log(object); // { name: \"Alice\", age: 30, email: \"alice@example.com\" }\n```\n\n## Requirements\n\n- **macOS 26+** with Apple Intelligence enabled\n- **Apple Silicon**: M1, M2, M3, or M4 chips\n- **Device Language**: Set to supported language (English, Spanish, French, etc.)\n- **Sufficient Storage**: At least 4GB available space for model files\n- **Bun**: Use Bun for best compatibility (see workspace rules)\n\n## API Reference\n\n### Native API\n\n#### `chat({ messages, schema?, tools?, stream?, ...options })`\n\n- `messages`: string or array of chat messages (`{ role, content }`)\n- `schema`: Zod schema or JSON Schema for structured/object output (optional)\n- `tools`: Array of tool definitions (see above) (optional)\n- `stream`: boolean for streaming output (optional)\n- `temperature`, `maxTokens`, etc.: generation options (optional)\n- Returns: `{ text, object?, toolCalls? }` or async iterator for streaming\n\n#### `appleAISDK.checkAvailability()`\n\nCheck if Apple Intelligence is available.\n\n#### `appleAISDK.getSupportedLanguages()`\n\nGet list of supported languages.\n\n### Vercel AI SDK Provider\n\n#### `createAppleAI(options?)`\n\nReturns a model provider for use with Vercel AI SDK (`generateText`, `streamText`, `generateObject`).\n\n#### `generateText({ model, messages, tools?, ... })`\n\nText generation with optional tool calling.\n\n#### `streamText({ model, messages, tools?, ... })`\n\nStreaming text generation with optional tool calling.\n\n#### `generateObject({ model, prompt, schema })`\n\nStructured/object generation.\n\n## Examples\n\nSee the `/examples` directory for comprehensive tests and usage:\n\n- `15-smoke-test.ts`: Native API, tool calling, streaming, structured output\n- `16-smoke-test.ts`: Vercel AI SDK compatibility, tool calling, streaming, object generation\n\n## Error Handling\n\n- All methods throw on fatal errors (e.g., invalid schema, unavailable model)\n- Streaming can be aborted with an `AbortController` (see Vercel AI SDK example)\n- Tool handler errors are surfaced in the result\n\n## Contributing\n\nContributions are welcome! Please read our contributing guidelines and submit pull requests.\n\n## License\n\nMIT License - see LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeridius-labs%2Fapple-on-device-ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeridius-labs%2Fapple-on-device-ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeridius-labs%2Fapple-on-device-ai/lists"}