
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-native-apple-llm
Advanced tools
React Native plugin for Apple Intelligence and Foundation Models
A React Native plugin to access Apple Intelligence Foundation Model framework using native on-device LLM APIs. This module lets you check model availability, create sessions, generate structured outputs (JSON), and generate with tools using Apple's LLMs, all from React Native. Note that this is a beta feature, so bugs and compatibility issues may rise. Issues are welcome.
npm install react-native-apple-llm
# or
yarn add react-native-apple-llm
# or
pnpm add react-native-apple-llm
npx pod-install
# or if using CocoaPods directly
cd ios && pod install
This plugin is perfect for building:
import {
isFoundationModelsEnabled,
AppleLLMSession
} from "react-native-apple-llm";
// Check if Apple Intelligence is available
const checkAvailability = async () => {
const status = await isFoundationModelsEnabled();
console.log("Apple Intelligence status:", status);
};
// Generate simple text
const generateSimpleText = async () => {
const session = new AppleLLMSession();
await session.configure({
instructions: "You are a helpful assistant."
});
const response = await session.generateText({
prompt: "Explain React Native in one sentence"
});
console.log(response);
session.dispose();
};
import {
AppleLLMSession,
ToolDefinition,
ToolSchema
} from "react-native-apple-llm";
// Define your tools
const weatherSchema: ToolSchema = {
name: "weather",
description: "Get the current weather in a given location",
parameters: {
city: {
type: "string",
description: "The city to get the weather for",
name: "city"
}
}
};
const weatherHandler = async (param: any) => {
return `The weather in ${param.city.value} is severe thunderstorms. Take shelter immediately.`;
};
const weatherTool: ToolDefinition = {
schema: weatherSchema,
handler: weatherHandler
};
// Use with session, don't forget to check availability first like above
const session = new AppleLLMSession();
await session.configure(
{
instructions: "You are a helpful assistant."
},
[weatherTool]
);
const response = await session.generateWithTools({
prompt: "What is the weather in Monrovia, California?"
});
console.log(response);
session.dispose();
The library supports streaming text generation in two ways, allowing you to display results as they're being generated:
generateTextStream() with async iterationimport { AppleLLMSession } from "react-native-apple-llm";
const streamExample = async () => {
const session = new AppleLLMSession();
await session.configure({
instructions: "You are an amazing storyteller."
});
// Use generateTextStream for streaming responses
const result = await session.generateTextStream({
prompt: "Tell me a story (in less than 100 words)."
});
// Iterate through the stream chunks
for await (const chunk of result) {
console.log(chunk); // Each chunk contains the full response text so far
// Update your UI with the chunk
}
session.dispose();
};
generateText() or generateWithTools()Both generateText() and generateWithTools() accept an optional stream parameter that receives chunks via events:
import { AppleLLMSession } from "react-native-apple-llm";
import { EventEmitter } from "events";
const streamWithEventEmitter = async () => {
const session = new AppleLLMSession();
await session.configure({
instructions: "You are a helpful assistant."
});
// Create an EventEmitter for streaming
const streamEmitter = new EventEmitter();
// Listen for data events
streamEmitter.on("data", (chunk: string) => {
console.log("Received chunk:", chunk);
// Update your UI with the chunk
});
// Pass the emitter to generateText or generateWithTools
await session.generateText({
prompt: "Explain React Native in detail.",
stream: streamEmitter
});
session.dispose();
};
The AppleLLMSession class provides context and tool management for each isolated session:
const session = new AppleLLMSession();
configure(options: LLMConfigOptions, tools?: ToolDefinition[]): Promise<boolean>Configures the session with instructions and optional tools.
await session.configure(
{
instructions: "You are a helpful assistant."
},
[weatherTool]
);
generateText(options: LLMGenerateTextOptions): Promise<any>Generates natural text responses.
const response = await session.generateText({
prompt: "Explain React Native"
});
generateStructuredOutput(options: LLMGenerateOptions): Promise<any>Generates structured JSON output.
const data = await session.generateStructuredOutput({
structure: { name: { type: "string" } },
prompt: "Extract name from: John Smith"
});
generateWithTools(options: LLMGenerateWithToolsOptions): Promise<any>Generates text with tool calling capabilities.
const response = await session.generateWithTools({
prompt: "What's the weather like?"
});
generateTextStream(options: LLMGenerateTextStreamOptions): ReadableStream<string>Generate text as a stream.
const stream = await session.generateTextStream({
prompt: "Tell me a story"
});
reset(): Promise<boolean>Resets the session state.
await session.reset();
dispose(): voidCleans up resources and event listeners.
session.dispose();
isFoundationModelsEnabled(): Promise<FoundationModelsAvailability>Checks if Foundation Models (Apple Intelligence) are enabled and available on the device.
Returns:
"available" - Apple Intelligence is ready to use"appleIntelligenceNotEnabled" - User needs to enable Apple Intelligence in Settings"modelNotReady" - Model is downloading or preparing (or mysterious system issues)"unavailable" - Device doesn't support Apple Intelligenceconst status = await isFoundationModelsEnabled();
if (status === "available") {
// Proceed with LLM operations
}
Deprecated: These functions are maintained for backward compatibility but are deprecated. Use the
AppleLLMSessionclass instead for better session management.
configureSession(options: LLMConfigOptions): Promise<boolean>Deprecated: Use AppleLLMSession.configure() instead.
Configures the LLM session with system instructions and behavior.
// Deprecated
await configureSession({
instructions: "You are an expert React Native developer."
});
// Recommended
const session = new AppleLLMSession();
await session.configure({
instructions: "You are an expert React Native developer."
});
generateStructuredOutput(options: LLMGenerateOptions): Promise<any>Deprecated: Use AppleLLMSession.generateStructuredOutput() instead.
// Deprecated
const userInfo = await generateStructuredOutput({
structure: {
name: { type: "string", description: "User's full name" },
age: { type: "number", description: "User's age" }
},
prompt: "Extract user information: John is 25 years old"
});
// Recommended
const session = new AppleLLMSession();
await session.configure({ instructions: "Extract user data." });
const userInfo = await session.generateStructuredOutput({
structure: {
name: { type: "string", description: "User's full name" },
age: { type: "number", description: "User's age" }
},
prompt: "Extract user information: John is 25 years old"
});
generateText(options: LLMGenerateTextOptions): Promise<string>Deprecated: Use AppleLLMSession.generateText() instead.
// Deprecated
const explanation = await generateText({
prompt: "Explain the benefits of on-device AI processing"
});
// Recommended
const session = new AppleLLMSession();
await session.configure({ instructions: "Be helpful and informative." });
const explanation = await session.generateText({
prompt: "Explain the benefits of on-device AI processing"
});
resetSession(): Promise<boolean>Deprecated: Use AppleLLMSession.reset() instead.
// Deprecated
await resetSession();
// Recommended
await session.reset();
Defines a property in your JSON schema:
interface StructureProperty {
type?: "string" | "integer" | "number" | "boolean" | "object";
description?: string;
enum?: string[];
properties?: StructureSchema;
}
A key-value mapping for defining structured output:
type StructureSchema = {
[key: string]: StructureProperty;
};
interface LLMConfigOptions {
instructions?: string;
}
interface LLMGenerateOptions {
structure: StructureSchema;
prompt: string;
}
interface LLMGenerateTextOptions {
prompt: string;
stream?: EventEmitter;
}
interface LLMGenerateTextStreamOptions {
prompt: string;
}
interface LLMGenerateWithToolsOptions {
prompt: string;
maxTokens?: number;
temperature?: number;
toolTimeout?: number; // in milliseconds
stream?: EventEmitter;
}
interface ToolSchema {
name: string;
description: string;
parameters: { [key: string]: ToolParameter };
}
interface ToolDefinition {
handler: (parameters: any) => Promise<any>; // parameter should always look like a json
schema: ToolSchema;
}
Apple Intelligence not available:
const status = await isFoundationModelsEnabled();
if (status === "appleIntelligenceNotEnabled") {
// Guide user to enable Apple Intelligence in Settings > Apple Intelligence & Siri
}
Model not ready:
if (status === "modelNotReady") {
// Apple Intelligence is downloading. Ask user to wait and try again. Or double check the device is properly configured
}
Device not supported:
if (status === "unavailable") {
// Device doesn't support Apple Intelligence. Consider fallback options.
}
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
yarn installyarn buildnpm linknpm link react-native-apple-llmMIT License - see LICENSE.md for details.
Star this repo if you find it helpful!
Created by Ahmed Kasem, Erik, and future contributors!
FAQs
React Native plugin for Apple Intelligence and Foundation Models
The npm package react-native-apple-llm receives a total of 392 weekly downloads. As such, react-native-apple-llm popularity was classified as not popular.
We found that react-native-apple-llm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.