## Improve startup speed

Reduce the wait before the first generated frame, and keep outfit changes responsive. First-frame time includes browser preparation, camera permission, network setup and inference startup; these steps vary by device and connection.

### 1. Prepare the runtime early

Call `prepareMirrorRuntime()` once when your try-on page loads, before the visitor presses Start. Keep its promise and await it before connecting. This prepares browser resources only: it does not create a session or consume API credits. It does not reserve an inference server.



```
import { prepareMirrorRuntime } from 'https://api.ikawn.com/sdk/mirror.js';
const runtimeReady = prepareMirrorRuntime();
// In your Start handler, before connecting:
await runtimeReady;
```



### 2. Keep the connection for garment changes

Reuse the active session and call `session.set({ referenceImage, prompt })` to change the garment or instructions. Do not disconnect and create another session for each outfit. Disconnect when the visitor is finished: a connected session continues to consume credits, even when the person is not moving.

### 3. Show the camera while the output starts

Request camera permission from a clear user action. Show a labelled local camera preview while connecting, then switch to the generated output when video frames arrive. A connected transport is not proof that a generated frame has arrived. Avoid showing an empty video element as if the try-on has failed.

### 4. Use clean references and a reliable connection

Use a clear garment image, avoid unnecessarily large uploads, and prepare references before connecting where practical. Use concise prompts and change only what is needed. Test on the actual browsers and mobile networks your customers use. Follow the [Safari and caching guide](https://platform.ikawn.com/documentation/browser-performance) for runtime caching and playback.

### 5. Measure the wait in separate stages

Record elapsed time for runtime preparation, camera permission, session creation, connection and the first decoded output frame. Use the SDK's `onStage` and `onStats` callbacks for diagnostics. Compare multiple warm and cold starts, including slow networks. Do not treat a single test as a latency guarantee.

### Startup and credits

Runtime preparation alone is free. Live session metering begins during signaling setup and can include the wait before the first visible generated frame. It does not begin only when the output is displayed. See [usage and credits](https://platform.ikawn.com/documentation/usage-billing) for the billing rules.

### Still slower than expected?

Share your browser and device, region, connection type, request or session ID, and the stage timings with [Support](https://platform.ikawn.com/support). Include whether the delay happens on the first start or every garment change. Never share a secret API key. There is no guaranteed startup time or dedicated pre-warm endpoint in the current public API.
