> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ai-coustics.com/llms.txt
> Use this file to discover all available pages before exploring further.

# WebAssembly initialization and lifecycle

> Initialize the module, choose an input source and manage owned handles.

**Version:** `@ai-coustics/aic-sdk-wasm` 0.23.0, Core SDK 0.23.0. [API index](/reference/sdk/api/wasm/index) · [WebAssembly quickstart](/reference/sdk/language-bindings/wasm).

Initialize the module once before loading models or constructing SDK objects. Processing, VAD and analysis calls are synchronous; the asynchronous initializer loads the module but does not turn processing into background work. A long loop can block the browser event loop and delay session requests. For background processing, initialize and own SDK objects inside a worker, then pass ordinary audio buffers through your application. Do not transfer SDK handles between workers or WebAssembly instances.

<span id="wasm-__wbg_init" />

## `__wbg_init`

```typescript theme={null}
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
```

The default export, conventionally imported as `init`, asynchronously instantiates the module. With no argument, it resolves `aic_sdk_wasm_bg.wasm` relative to the JavaScript module URL and fetches it. Serve both package files through your bundler or web server.

Prefer the object form, for example `await init({ module_or_path: wasmUrl })`. The older bare input form remains accepted but logs a deprecation warning. A directly supplied `Request`, URL or string is fetched. A `Response`, byte buffer or compiled module can be supplied directly or through a promise. Although the declaration permits `Promise<InitInput>`, this release checks whether to fetch before awaiting the input. Resolve promises of URLs, strings or requests yourself before passing their value to the initializer; a promise of a URL is not fetched automatically. HTTP, fetch and WebAssembly compilation/instantiation failures reject the promise. Correct `application/wasm` MIME enables streaming instantiation; the loader can fall back to buffering for an unsuitable MIME type.

After successful initialization, later calls return the already initialized instance. Complete one initialization before using the SDK; do not rely on simultaneous first calls sharing an in-flight promise.

<span id="wasm-initsync" />

## `initSync`

```typescript theme={null}
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
```

Synchronously instantiates already available bytes or a compiled `WebAssembly.Module`. Prefer `initSync({ module: bytes })`; the bare form is deprecated. It performs no download and throws if compilation or instantiation fails. It returns the already initialized instance if initialization has completed. Use the asynchronous initializer when bytes still need to be fetched.

<span id="wasm-initinput" />

## `InitInput`

```typescript theme={null}
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
```

Accepted input forms for the asynchronous initializer. A string URL is included through `RequestInfo`.

<span id="wasm-syncinitinput" />

## `SyncInitInput`

```typescript theme={null}
export type SyncInitInput = BufferSource | WebAssembly.Module;
```

Accepted input forms for `initSync`. Fetch or read the bytes before calling it.

<span id="wasm-initoutput" />

## `InitOutput`

```typescript theme={null}
export interface InitOutput
```

The initializer returns the generated raw WebAssembly export object. Application code normally ignores it and uses the exported JavaScript classes. Its `memory` field is a `WebAssembly.Memory`; its remaining fields contain raw pointer-level calls, allocation helpers, tables and binding internals. These generated ABI members are excluded from the application API documented here. Do not call their raw constructors or destructors, mix pointers with JavaScript handles or rely on their names across builds. The installed package's `.d.ts` contains the complete ABI declaration.

<span id="wasm-__aic_sdk_wasm_init" />

## `__aic_sdk_wasm_init`

```typescript theme={null}
export function __aic_sdk_wasm_init(): void;
```

Generated startup hook invoked by module initialization. It sets up panic reporting and SDK wrapper identification. It is exported for binding startup, not for application initialization; use the default export or `initSync` instead.

## Ownership and cleanup

`Model`, `Processor`, `ProcessorContext`, `Vad`, `VadContext`, `Analyzer` and `AnalysisResult` all own WebAssembly allocations. Every returned handle needs its own `free()` call, including repeated context queries and each analysis result. Methods and properties require a live handle. Do not call `free()` twice, use a freed handle or pass a handle from a different module instance.

When the runtime supports `Symbol.dispose`, the package aliases it to `free()` on all seven classes. Otherwise, use explicit `finally` cleanup. Finalization support does not guarantee when memory will be reclaimed.

Terminate a processing or analysis session when finished and free the corresponding handle separately. The termination method returns `void`; it does not wait for the request to reach the server. Keep persistent SDK keys on your backend and pass short-lived JWTs to browser constructors. See [authentication](/models/get-started/authenticate-apps) for the token flow.
