Skip to main content
This reference describes host interfaces available in official releases, with version differences noted in the relevant sections. See the Client API guide for examples and Capabilities and progress for version support.

Entry and availability

The host injects window.mcode into a managed Mini App’s main page through preload. No runtime SDK or plugin ID is required. Ordinary browsers, other pages, and older hosts may omit these objects, so check before calling.The table lists page namespaces. host is available from v3.1.11; the other entries were already available in v3.1.6. Presence does not establish a manifest declaration or an enabled permission: permission-protected calls are checked against page identity, declarations, and switches. Node uses the separate Node API.Page message, window, speech, tool, and Agent APIs reject with a lowercase code in Error.message; do not rely on Node’s additional error fields. host methods instead reject with a plain object { code, message: code }, and subscription errors use onError. See the page error convention.

host

From MiniMax Code v3.1.11, miniapp.host provides the following page APIs. Older hosts may omit this namespace, so check window.mcode?.miniapp?.host first. Node has no context.host. See the Host guide for examples.

ui.getState / ui.subscribe

Neither read requires hostAccess or session.read. The page applies its own styles and translations. State contains no account, location, or other settings. Use the Mini App’s defaults if the API is missing or temporarily unavailable.

navigation.getState / navigation.subscribe

getState() takes no arguments and returns not_permitted while hidden. An authorized subscription may be established before the page is shown; it stays paused and delivers its full baseline on first visibility. It records no hidden history and sends only the latest state on return.State contains no session ID, URL, or content. Do not pass key to open() or use it to correlate plugins. Observing a host conversation change does not rebind the Mini App’s original conversation; default Agent calls and message.append retain their original target.

navigation.open(target)

Opening follows the host’s existing leave and save guards. Missing and inaccessible sessions both return target_unavailable. Opening settings preserves the underlying page and drafts; unsaved settings are checked when settings actually close or change sections.A pop-out remains bound to its original host window, regardless of system focus. If that window is destroyed, the old page’s Host calls return host_unavailable. If navigation ends the calling document, its Promise continuation may not run. The host waits up to 60 seconds for presentation, then returns result_unknown; inspect the current interface rather than automatically repeating an operation with UI side effects.

Subscriptions and errors

subscribe() establishes reception before providing the baseline, so do not assemble a separate read-then-listen sequence. Each page may keep at most 64 Host subscriptions. Call dispose() when done; leaving the page also cleans them up. Listener exceptions are logged to the console and do not end a subscription.Invalid arguments, setup failures, and subscription termination use options.onError({ code, message: code }), or the console when onError is absent. Revocation ends navigation subscriptions, and losing the owning host ends affected subscriptions. A temporarily unreachable permission source gives host_unavailable; an undeclared or disabled permission gives not_permitted. Subscribe again after recovery; old subscriptions do not resume automatically.Host Promises reject with a plain object { code, message: code }; do not depend on instanceof Error. See Host error codes for the seven MiniAppHostErrorCode values and recovery. A new document must read or subscribe again; old document subscriptions and pending Promises do not carry over.

message.append

Every call opens host confirmation, with no remembered choice. Even an empty string needs confirmation, but leaves the draft unchanged. After confirmation, the host preserves existing text, references, and attachments, and appends the new text. Resolution means the append completed, not that a message was sent or an Agent ran.The target is the local, writable session containing the page. An unavailable target does not fall back to another session, a home draft, or a new session. This API grants no session reads and cannot change sent messages. There is no page cancellation parameter; the user can refuse the confirmation. After result_unknown, inspect the input before deciding to retry.Errors are user_cancelled, invalid_request, text_too_large, not_allowed, target_unavailable, and result_unknown; see Error codes.

window

The window handle interface may change, so feature-detect before use. It controls only its calling page’s window. id is a stable opaque string, not a session or run ID; popping out or returning to the file panel does not change it.

State fields

getState() takes no arguments. inline means the page is in the file panel, with no window field. window means a separate window, with every field below.Either state may also return a top-level modeChangeReloadsPage field indicating whether a mode change rebuilds the page; see Page rebuilds and confirmation.

update(patch)

A successful reply contains the full MiniAppWindowState. All fields are optional; omitted or undefined fields remain unchanged, and an empty object is valid. Unknown fields, wrong types, and non-finite numbers fail with invalid_request. In v3.1.10, cancelling window-transfer confirmation resolves with the current state and the original mode: a successful reply does not prove that the requested mode took effect. See Page rebuilds and confirmation.When updating x, y, width, or height, the host checks the final content rectangle after rounding and applying minimum dimensions. It must overlap the same display work area by at least 40 px on both axes; otherwise the update fails with not_permitted. This rule also applies to size-only updates, not just window moves.Updates without mode in the same animation frame are merged, with later fields winning. All callers in that frame share one result or rejection. A mode update is sent immediately to preserve its user gesture.

focus()

Takes no arguments and returns Promise<void>. A user gesture is required. A separate window is restored from minimization, shown, and focused; an inline page requests host focus and selects its own tab. Do not rely on it to expand a collapsed file panel. It does not create a page or control another Mini App.

onDidChangeState(listener)

Synchronously returns { dispose() }. A non-function listener synchronously throws Error('invalid_request'). An update() delivers state if the current document remains alive and receives a successful reply. This does not prove that mode changed; inspect the delivered state. While the document remains alive, periodic checks detect external changes such as dragging a window, with no guarantee of every intermediate state. Initial subscription does not immediately deliver an initial value; call getState() for one.Call dispose() to unsubscribe; leaving the page also clears listeners. A throwing listener does not interrupt a window update. Window errors are inline_mode, not_permitted, busy, result_unknown, and invalid_request. After result_unknown, use getState() to reconcile; see Window errors.

Page rebuilds and confirmation

Official releases from v3.1.9 may return the optional modeChangeReloadsPage?: boolean field. Check the runtime result of getState(); this field is not an update patch option. When it is true, an actual change between inline and window rebuilds the page. Hosts that move the native page do not return this flag, so not every window transfer reloads the page.A rebuild preserves the logical window ID and Node service, but the current document, JavaScript memory, media streams, page subscriptions, and pending page Promises do not survive. Save necessary state first. Do not put required work after await update({ mode }) or wait for the old document’s onDidChangeState to confirm completion. When the destination document starts, call getState(), restore saved content, and subscribe again. An absent flag does not guarantee that a host reload, crash, or another page-ending event cannot end the document.From v3.1.10, popping out or returning a page that requires rebuilding first displays the impact in the main host window and waits for user confirmation. Closing the separate window or pressing Cmd/Ctrl+W uses the same flow; the original window is not hidden or destroyed while waiting. Cancellation leaves the page, requests, and window intact. update() resolves with the current state, whose mode may still be the original value, rather than rejecting with user_cancelled. After confirmation, the old page’s requests and subscriptions are cancelled or cleaned up when the page ends. Completed operations are not undone, and requests are not replayed automatically.

speech.transcribe

Declare deviceAccess: ["microphone"] and keep its switch on. The page captures audio, chooses the utterance boundary, converts samples, and stops all media tracks. The host transcribes the complete utterance; onPartial is not live recognition while recording. Do not pass WAV, WebM, Ogg, FLAC, MP3, or MediaRecorder output directly.Only one transcription per Mini App can run at once; another gets busy. There is no page signal or cancel() parameter. Ending the page aborts the in-flight transcription, and host processing has a 180-second deadline. Switching microphone access off refuses later calls without forcibly stopping a media stream the page already owns.Errors are invalid_request, not_permitted, audio_too_large, busy, runtime_unavailable, transcription_failed, and result_unknown; see Speech errors. See the guide for recording examples.

tool.request

Declare toolAccess: ["call"], keep the Node service running, and invoke directly from a user gesture. The host asks only about tools still at ask, letting the user tick which to always allow. Leaving a box unticked or refusing does not necessarily reject the entire request: it returns actual permissions. Entries already allow or deny are not changed by this request.When the tool-calling switch is off, the method returns deny for every requested name without a prompt. Without toolAccess there is no usable tool session; an unavailable Node tool session or channel rejects with runtime_unavailable. The page has neither tool list() nor call(), nor a cancellation parameter for this method. Actual calls use the Node tool API, and the host judges permission again on every call.Errors are invalid_request, not_permitted, approval_required, runtime_unavailable, and result_unknown; see Tool permission errors. Read the rejection’s Error.message; do not rely on the permissions field attached to Node-side errors.

capabilities.has

Returns a boolean synchronously without asking for permission or making an async host call. Unknown names return false; a non-string passed at runtime also returns false. Older hosts may omit capabilities, so use miniapp?.capabilities?.has(name).This table lists all 19 names in v3.1.11 and v3.1.12. The five host.* names are available from v3.1.11. The table is fixed per host version and shared by the page and Node. true means the host implements the feature, not that the current side has that object, the manifest declared it, or the user granted it.agent.reply, agent.answer, and agent.cancel are not separate capability names; do not probe those names to infer method support. Check each API’s availability and permission requirements as well.

Agent namespace

For page miniapp.agent methods (run, reply, answer, cancel, open, catalogs, and session observation), including parameter differences from Node, see the Agent API reference.

Camera and system notifications

These capabilities are supported from MiniMax Code v3.1.9. They use standard browser APIs, with no new host namespace or capability-detection name. Declare the minimum version in engines.mcode and the required items in deviceAccess; users can turn access off in plugin details.A combined audio/video request requires both microphone and camera to be declared and enabled. Turning a permission off blocks new capture requests; the page must still stop media streams it already holds. Standard capture errors, such as NotAllowedError, come from the browser API and do not use host speech-transcription error codes.A notification click handler can call the window handle’s focus() while the original page remains alive. Do not rely on it to expand a collapsed file panel. After that page closes or reloads, an old notification cannot reopen it. This API does not provide background notifications after the page closes.See the Camera and System notifications guides for examples and limits.