Foundry Local runs AI models directly on Android devices. ApiExplorerAppIPC shows the new shared API in IPC mode with a simple Compose screen for the full model lifecycle.
fun runModel(modelAlias: String) {
lifecycleScope.launch {
val manager = FoundryLocalManager.create(
context = context,
config = Configuration(appName = "ApiExplorerAppIPC"),
onDisconnected = { /* update UI */ }
)
val catalog = manager.getCatalog()
val model = catalog.getModel(modelAlias)
model.download(progress = { pct -> println(pct) }, contentIntent = null, timeoutMinutes = 30)
model.load()
val chatClient = model.createChatClient()
val response = chatClient.completeChat(
ChatCompletionRequest(messages = listOf(ChatMessage.user("Hello")))
)
println(response.message?.content)
}
}The application supplies modelAlias from its model selection or configuration.
- Connect to the Foundry Local service with
FoundryLocalManager.create(...) - List the catalog with
catalog.listModels() - Download a model with coroutine progress callbacks and cancel via
Job.cancel() - Load and unload the model with suspend functions
- Run synchronous chat with
completeChat(...) - Run streaming chat with
completeChatStreaming(...).collect { ... } - Remove the cached model with
removeFromCache() - Recover after disconnects with
isConnectedandreconnect()
Good to know: Release AARs are not committed to this repository. Place the verified IPC AAR in this sample's
libs/directory before building.
-
Download
foundry-local-ipc-sdk-<version>.aarfrom the matching GitHub Release, verify its published SHA-256 hash, and place it in:examples/ipc/ApiExplorerAppIPC/libs/ -
Install the Foundry Local service app from Google Play.
-
Build the app from the repository root:
./gradlew :ApiExplorerAppIPC:assembleDebug
-
Connect an Android device and install the app:
./gradlew :ApiExplorerAppIPC:installDebug
-
Open API Explorer IPC from the device launcher.
Good to know: Keep only one IPC AAR in the sample's
libs/directory. Gradle loads every AAR in that directory, and multiple versions cause duplicate-class errors.
Good to know: This example uses the shared API package
com.microsoft.foundrylocal.api.*only. It does not use the older IPC-specific callback API,FLResult, or AIDL callback stubs.