> ## 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 model API

> Load model bytes and inspect model metadata.

**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).

<span id="wasm-model" />

## `Model`

```typescript theme={null}
export class Model
```

A loaded model and its metadata. Create it with `Model.fromBytes`; its constructor is private. Model storage is retained by each processor, VAD or analyzer created from it. Those instances remain valid if the original `Model` handle is freed.

<span id="wasm-model-free" />

### `Model.free`

```typescript theme={null}
free(): void;
```

Releases the owned WebAssembly allocation. Call once in `finally` and do not use the handle afterward. Garbage collection does not guarantee timely cleanup; `free()` does not acknowledge session termination. Dependent processors, VAD instances and analyzers retain shared model storage until they are freed.

<span id="wasm-model-symbol-dispose" />

### `Model.Symbol.dispose`

```typescript theme={null}
[Symbol.dispose](): void;
```

Aliases `free()` when the runtime supports `Symbol.dispose`; do not call both on the same handle. Otherwise, call `free()` in `finally`.

<span id="wasm-model-frombytes" />

### `Model.fromBytes`

```typescript theme={null}
static fromBytes(bytes: Uint8Array): Model;
```

Loads an `.aicmodel` from `bytes` and returns a new model. The wrapper copies bytes into owned aligned storage; the caller may release or change the original `Uint8Array` after this call. Loading can throw for invalid, incompatible or unsupported data, or allocation failure. There is no `Model.download` or `Model.fromFile` in this package. Fetch the bytes asynchronously in your application, then call this synchronous factory.

<span id="wasm-model-getid" />

### `Model.getId`

```typescript theme={null}
getId(): string;
```

Returns the model ID embedded in the loaded file as a JavaScript string. This is a metadata query and does not require a credential.

<span id="wasm-model-getoptimalblocksize" />

### `Model.getOptimalBlockSize`

```typescript theme={null}
getOptimalBlockSize(sample_rate: number): number;
```

Returns the preferred mono block size, in samples, for the requested whole-number host sample rate in Hz. Query the rate you will actually initialize. The query computes a size; it is not a substitute for initialization validation.

<span id="wasm-model-getoptimalsamplerate" />

### `Model.getOptimalSampleRate`

```typescript theme={null}
getOptimalSampleRate(): number;
```

Returns the model's native sample rate in Hz. Use this as the starting point for initialization; other supported host rates require adaptation.

<span id="wasm-getversion" />

## `getVersion`

```typescript theme={null}
export function getVersion(): string;
```

Returns this WebAssembly wrapper's package version, `0.23.0` for this release. It is not a query of a separately installed native library.

<span id="wasm-getcompatiblemodelversion" />

## `getCompatibleModelVersion`

```typescript theme={null}
export function getCompatibleModelVersion(): number;
```

Returns the model format version supported by the compiled runtime. This is a format compatibility number, not a model ID or package release version. Model loading still validates the supplied file.

## Fetch and inspect a model

After initialization, fetch a model URL supplied by your application. This helper checks the HTTP response and frees the loaded model after reading its metadata. It requires no SDK credential.

```javascript theme={null}
import init, { Model, getVersion } from "@ai-coustics/aic-sdk-wasm";

export async function inspectModel(modelUrl) {
  await init();
  const response = await fetch(modelUrl);
  if (!response.ok) {
    throw new Error(`Model download failed: ${response.status}`);
  }
  const bytes = new Uint8Array(await response.arrayBuffer());
  const model = Model.fromBytes(bytes);
  try {
    const sampleRate = model.getOptimalSampleRate();
    return {
      sdkVersion: getVersion(),
      modelId: model.getId(),
      sampleRate,
      blockSize: model.getOptimalBlockSize(sampleRate),
    };
  } finally {
    model.free();
  }
}
```
