Melange
API Reference

Cache Management

Download models in the background and remove downloaded model artifacts.

ZeticMLangeModel and ZeticMLangeLLMModel let an app download a model before it is needed, observe or stop that work, and later remove the downloaded artifacts.

Background Model Downloads

downloadInBackground schedules a durable SDK download without constructing a model runtime. Keep the returned BackgroundDownloadHandle to check its state or stop it later.

The download can continue after the app moves to the background. On iOS, the app must await scheduling while foregrounded and forward background URL-session events; see iOS advanced configuration. Flutter apps targeting iOS need the same host-app setup; see Flutter advanced configuration.

The following APIs are available on both ZeticMLangeModel and ZeticMLangeLLMModel:

  • downloadInBackground(...) schedules the download and returns a handle.
  • getBackgroundDownloadStatus(...) returns the latest durable state for that handle.
  • stopBackgroundDownload(...) cancels an active download without deleting an installed model.
  • removeDownloadedModel(...) stops active downloads for the selected model and removes its SDK-managed artifacts.

Download States

BackgroundDownloadStatus reports the handle, its state, downloaded bytes, optional total bytes, and an optional error message. Flutter also exposes progress and isTerminal.

StateMeaning
queuedThe SDK accepted the download request.
resolvingThe SDK is resolving the selected model artifact.
downloadingArtifact bytes are being transferred.
verifyingThe downloaded artifact is being checked before installation.
installedThe artifact is ready for a later model initialization.
failedThe download did not complete; inspect the error message when present.
stoppedThe app stopped the active download.

Android represents these states with uppercase enum cases; iOS and Flutter use the lowercase names shown above.

Stop and Removal Results

stopBackgroundDownload returns stopped when it cancels active work, alreadyFinished for a terminal job, and notFound when the handle is unknown. Stopping a download preserves any model that is already installed.

Android returns the uppercase enum cases STOPPED, ALREADY_FINISHED, and NOT_FOUND. iOS uses .stopped, .alreadyFinished, and .notFound; Flutter uses stopped, alreadyFinished, and notFound.

removeDownloadedModel returns ModelRemovalResult. Check isInUse before treating removal as complete: close active model instances and retry if it is true. The result also reports whether anything was removed plus the deleted file count and bytes.

Cache Handling Policy

cacheHandlingPolicy controls SDK-managed model artifacts on disk. Background-download APIs default to KEEP_EXISTING / keepExisting; model constructors and create APIs default to REMOVE_OVERLAPPING / removeOverlapping.

For LLMs, this setting is separate from kvCacheCleanupPolicy, which controls in-memory conversation KV cache behavior.

Platform References

On this page