Skip to main content
This beta feature is currently unavailable. We are moving off a dependency that is no longer open source and onto our own local AI infrastructure, so that every Despia user gets a fully open source, license-compliant experience.

Run language models on-device with one function call. Models load via the device’s native AI acceleration stack. Inference jobs auto-resume across backgrounding. Downloads continue when users close the app.

Installation


Runtime detection

The SDK resolves runtime state once at import time and exposes it synchronously. Gate every call behind intelligence.runtime.ok so the same code works in a desktop browser preview.
When ok is false, every API returns a not-ready handle. models.available() resolves to an empty array. The SDK never throws on a missing runtime, so your code can branch cleanly without try/catch.

Run

Fire an inference job and wire callbacks for streaming tokens and the final result.
stream(chunk) receives the full accumulated text so far, not a delta. Use el.textContent = chunk (replace), never el.textContent += chunk (append). Appending will produce exponentially duplicated output.
string
required
Routes the call. 'text' is the only enabled value in this release.
string
required
Model id, e.g. 'qwen3-0.6b'. Must be installed first via models.download().
string
required
The user prompt
string
System-level instruction context for the session
boolean
When true, fires stream callbacks as tokens generate
Any extra key on the params object is forwarded to the native layer as-is. Arrays become comma-separated after URL encoding. You do not need to encode values yourself.

Handler callbacks

(chunk: string) => void
Fires for each snapshot. chunk is the full accumulated text so far, not a delta.
(text: string) => void
Fires once when inference finishes. text is the complete response string.
(err: { code, message }) => void
Fires on failure. See error codes.
(intent: object) => void
Optional notification hook. Fires once per active job on focusout. Use for UI affordances or analytics. Resume itself is automatic.

Returns

run() returns a call handle synchronously. The same destructure works whether the runtime is ready or not.
boolean
true when the runtime is ready and the call was queued, false when not
object | null
The original params object, storable and re-firable. null on the not-ready handle.
() => void
Removes this job from the SDK. No further callbacks fire.

Models

Manage the on-device model catalogue. Models are downloaded from Hugging Face into the Despia container and reused across launches.
() => Promise<Model[]>
Full catalogue the runtime can install. Returns [] when runtime.ok is false.
() => Promise<Model[]>
Currently downloaded to this device
(id, { onStart, onProgress, onEnd, onError }) => void
Starts a background download. Fire-and-forget, results arrive via the callback object.
(id: string) => Promise
Remove one model by id
() => Promise
Remove every downloaded model

Download events

Per-call callbacks for the component that started the download. Global events for app-wide state that needs to survive anything, including a force-quit mid-download.
(modelId: string) => void
Fires when a download begins
(modelId: string, pct: number) => void
Fires on progress updates. pct is a 0 to 100 integer in both the global event and the per-call onProgress callback.
(modelId: string) => void
Fires when a download completes successfully
(modelId: string, err: object) => void
Fires on download failure
The pattern: session callbacks for in-session UX (a progress bar on the settings page), global events for permanent state (a tab bar badge that needs to survive a force-quit).

Background and return

Inference sessions do not survive backgrounding. The native context is torn down when iOS or Android suspend the WebView. The SDK handles this for you. Every in-flight job is re-fired automatically with the same params and the same handler when the user returns. Just write your code as if backgrounding does not exist. The SDK only re-fires jobs that were genuinely interrupted: jobs that complete normally never re-fire, jobs that error out never re-fire, jobs you explicitly .cancel() never re-fire. Any number of concurrent jobs all resume.

Error codes


React hook


Environment check

The SDK never throws when the runtime is missing. It returns a not-ready handle so your code can branch cleanly. The same code path works in the Despia WebView and in a desktop browser preview.

Resources

NPM Package

despia-intelligence

Introduction

Overview, model selection, and FAQs

GitHub

Source on GitHub