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

# Using the Muna Client

> Run any compiled model with the native Muna client.

Muna's native client, `muna.predictions`, runs any compiled model locally.

## Creating Predictions

```ts JavaScript icon="js" theme={null}
import { Muna } from "muna"

// 💥 Create your Muna client
const muna = new Muna({ accessKey: "..." });

// 🔥 Run inference locally
const prediction = await muna.predictions.create({
    tag: "@fxn/greeting",
    inputs: { name: "Yusuf" }
});

// 🚀 Print the result
console.log(prediction.results[0]);
```

```py Python icon="python" theme={null}
from muna import Muna

# 💥 Create your Muna client
muna = Muna(access_key="...")

# 🔥 Run inference locally
prediction = muna.predictions.create(
    tag="@fxn/greeting",
    inputs={ "name": "Muna" }
)

# 🚀 Use the results
print(prediction.results[0])
```

```ts React Native icon="react" theme={null}
import { Muna } from "@muna/expo"

// 💥 Create your Muna client
const muna = new Muna({ accessKey: "..." });

// 🔥 Run inference locally
const prediction = await muna.predictions.create({
    tag: "@fxn/greeting",
    inputs: { name: "Yusuf" }
});

// 🚀 Print the result
console.log(prediction.results[0]);
```

```swift iOS icon="swift" theme={null}
import Muna

// 💥 Create your Muna client
let muna = Muna(accessKey: "...")

// 🔥 Run inference locally
let prediction = try await muna.predictions.create(
    tag: "@fxn/greeting",
    inputs: [ "name": "Terri" ]
)

// 🚀 Use the results
print("\(prediction.results![0]!)")
```

```kt Android icon="android" theme={null}
import ai.muna.muna.Muna

// 💥 Create your Muna client
val muna = Muna("...")

// 🔥 Run inference locally
val prediction = muna.predictions.create(
    "@fxn/greeting",
    mapOf("name" to "Timi")
)

// 🚀 Use the results
println(prediction.results!![0])
```

```csharp Unity icon="unity" theme={null}
using Muna;

// 💥 Create your Muna client
var muna = new Muna(accessKey: "...");

// 🔥 Run inference locally
var prediction = await muna.Predictions.Create(
    tag: "@fxn/greeting",
    inputs: new() { ["name"] = "Peter" }
);

// 🚀 Use the results
Debug.Log(prediction.results[0]);
```

```rust Rust icon="rust" theme={null}
use std::collections::HashMap;
use muna::{Muna, Value};

// 💥 Create your Muna client
let muna = Muna::new(Some("..."), None);

// 🔥 Run inference locally
let mut inputs = HashMap::new();
inputs.insert("name".to_string(), "Yusuf".into());
let prediction = muna.predictions.create(
    "@fxn/greeting",
    Some(inputs),
    None,
    None,
    None,
    None,
).await.unwrap();

// 🚀 Print the result
println!("{:?}", prediction.results.unwrap()[0]);
```

## Streaming Predictions

Muna supports consuming the partial results of an inference request as they are made available by the compiled model:

```ts JavaScript icon="js" theme={null}
// 🔥 Create an inference stream
const stream = await muna.predictions.stream({
  tag: "@text-co/split-sentence",
  inputs: { text: "Hello world" }
});

// 🚀 Consume the stream
for await (const prediction of stream)
  console.log(prediction.results[0]);
```

```py Python icon="python" theme={null}
# 🔥 Create an inference stream
stream = muna.predictions.stream(
  tag="@text-co/split-sentence",
  inputs={ "text": "Hello world" }
)

# 🚀 Consume the stream
for prediction in stream:
  print(prediction.results[0])
```

```ts React Native icon="react" theme={null}
// 🔥 Create an inference stream
const stream = await muna.predictions.stream({
  tag: "@text-co/split-sentence",
  inputs: { text: "Hello world" }
});

// 🚀 Consume the stream
for await (const prediction of stream)
  console.log(prediction.results[0]);
```

```swift iOS icon="swift" theme={null}
// 🔥 Create an inference stream
let stream = try await muna.predictions.stream(
  tag: "@text-co/split-sentence",
  inputs: ["text": "Hello world"],
)

// 🚀 Consume the stream
for try await prediction in stream {
  print("\(prediction.results?[0])")
}
```

```kt Android icon="android" theme={null}
// 🔥 Create an inference stream
val stream = muna.predictions.stream(
  "@text-co/split-sentence",
  mapOf("text" to "Hello world")
)

// 🚀 Consume the stream
stream.use {
  for (prediction in it.consume())
    println(prediction.results!![0])
}
```

```csharp Unity icon="unity" theme={null}
// 🔥 Create an inference stream
var stream = await muna.Predictions.Stream(
  tag: "@text-co/split-sentence",
  inputs: new() { ["text"] = "Hello world" }
);

// 🚀 Consume the stream
await foreach (var prediction in stream)
  Debug.Log(prediction.results[0]);
```

```rust Rust icon="rust" theme={null}
use std::collections::HashMap;
use futures_util::StreamExt;

// 🔥 Create an inference stream
let mut inputs = HashMap::new();
inputs.insert("text".to_string(), "Hello world".into());
let mut stream = muna.predictions.stream(
  "@text-co/split-sentence",
  inputs,
  None,
  None,
).await.unwrap();

// 🚀 Consume the stream
while let Some(Ok(prediction)) = stream.next().await {
  println!("{:?}", prediction.results.unwrap()[0]);
}
```

### Consuming Inference Streams

Streaming in Muna is designed to fully separate how a compiled function
is implemented from how the function might be consumed. Consider these two functions:

```py eager.py icon="python" theme={null}
def predict() -> str:
    return "hello from Muna"
```

```py generator.py icon="python" theme={null}
def predict() -> Iterator[str]:
    yield "hello"
    yield "hello from"
    yield "hello from Muna"
```

Here are the results of creating vs. streaming each function at runtime:

> [accordion] Using predictions.create with eager.py
>
> In this case, the single result is returned:
>
> ```ts icon="js" theme={null}
> // Run inference with the eager function
> const prediction = await muna.predictions.create({
>   tag: "@muna/eager",
>   inputs: { }
> });
>
> // Display the results
> console.log(prediction.results[0]);
>
> // Outputs:
> // "hello from Muna"
> ```

> [accordion] Using predictions.create with generator.py
>
> In this case, the Muna client will consume all partial results yielded
> by the function then return **the very last one**:
>
> ```ts icon="js" theme={null}
> // Run inference with the generator function
> const prediction = await muna.predictions.create({
>   tag: "@muna/generator",
>   inputs: { }
> });
>
> // Display the results
> console.log(prediction.results[0]);
>
> // Outputs:
> // "hello from Muna"
> ```

> [accordion] Using predictions.stream with eager.py
>
> In this case, the Muna client will return an inference stream with the single result returned by the function:
>
> ```ts icon="js" theme={null}
> // Create an inference stream with the eager function
> const stream = await muna.predictions.stream({
>   tag: "@muna/eager",
>   inputs: { }
> });
>
> // Display the results
> for await (const prediction of stream)
>   console.log(prediction.results[0]);
>
> // Outputs:
> // "hello from Muna"
> ```

> [accordion] Using predictions.stream with generator.py
>
> In this case, the Muna client will provide an inference stream containing all
> partial results yielded by the function:
>
> ```ts icon="js" theme={null}
> // Create an inference stream with the generator function
> const stream = await muna.predictions.stream({
>   tag: "@muna/generator",
>   inputs: { }
> });
>
> // Display the results
> for await (const prediction of stream)
>   console.log(prediction.results[0]);
>
> // Outputs:
> // "hello"
> // "hello from"
> // "hello from Muna"
> ```

> [!TIP]
>
> You can choose how to consume a compiled function depending on what works best for your user experience.
> You don't have to care about the underlying function!

## Using Inference Values

Muna supports a fixed set of value types for inference input and output values:

> [accordion] Floating Point Values
>
> Muna supports the following floating-point numbers:
>
> | Muna value type | C/C++ type | Description |
> | :- | :- | :- |
> | `float16` | [`float16_t`](https://en.cppreference.com/w/cpp/types/floating-point) | IEEE 754 16-bit floating point number. |
> | `float32` | `float` | IEEE 754 32-bit floating point number. |
> | `float64` | `double` | IEEE 754 64-bit floating point number. |
>
> ```ts JavaScript icon="js" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         radius: 4.5
>     }
> });
> const radius = prediction.results[0] as number;
> ```
>
> ```py Python icon="python" theme={null}
> prediction = muna.predictions.create(
>     tag="@fxn/identity",
>     inputs={
>         "radius": 4.5
>     }
> )
> radius: float = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         radius: 4.5
>     }
> });
> const radius = prediction.results[0] as number;
> ```
>
> ```swift iOS icon="swift" theme={null}
> let prediction = try await muna.predictions.create(
>     tag: "@fxn/identity",
>     inputs: [
>         "radius": 4.5
>     ]
> )
> let radius = prediction.results![0] as! Float
> ```
>
> ```kt Android icon="android" theme={null}
> val prediction = muna.predictions.create(
>     "@fxn/identity",
>     mapOf(
>         "radius" to 4.5f
>     )
> );
> val radius = (Float)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/identity",
>     inputs: new() {
>         ["radius"] = 4.5f
>     }
> );
> var radius = (float)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> let mut inputs = HashMap::new();
> inputs.insert("radius".to_string(), 4.5f32.into());
> let prediction = muna.predictions.create(
>     "@fxn/identity",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Float(radius) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> > [!TIP]
> >
> > In languages that don't support fixed-size floating point scalars, the data type for floating point values
> > defaults to `float32`. Use a tensor constructor to explicitly specify the data type.
>
> > [!NOTE]
> >
> > Support for half-precision floating point scalars `float16` is planned for the future depending on language support.
>
> Muna supports floating point vectors (i.e. one-dimensional floating point tensors):
>
> ```ts JavaScript icon="js" theme={null}
> import type { Tensor } from "muna"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         vector: new Float32Array([ 1.2, 2.2, 3.2, 4.5 ])
>     }
> });
> const vector = prediction.results[0] as Tensor;
> ```
>
> ```py Python icon="python" theme={null}
> import numpy as np
>
> prediction = muna.predictions.create(
>     tag="@fxn/identity",
>     inputs={
>         "vector": np.array([1.2, 2.2, 3.2, 4.5], dtype="float32")
>     }
> )
> vector: np.ndarray = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> import type { Tensor } from "@muna/expo"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         vector: new Float32Array([ 1.2, 2.2, 3.2, 4.5 ])
>     }
> });
> const vector = prediction.results[0] as Tensor;
> ```
>
> ```kt Android icon="android" theme={null}
> import ai.muna.muna.types.Float32Tensor;
>
> val prediction = muna.predictions.create(
>     "@fxn/identity",
>     mapOf(
>         "vector" to floatArrayOf(1.2f, 2.2f, 3.2f, 4.5f)
>     )
> );
> val vector = (Float32Tensor)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/identity",
>     inputs: new() {
>         ["vector"] = new [] { 1.2f, 2.2f, 3.2f, 4.5f }
>     }
> );
> var vector = (Tensor<float>)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> use muna::{Value, Tensor, TensorData};
>
> let mut inputs = HashMap::new();
> inputs.insert("vector".to_string(), Value::Tensor(Tensor {
>     data: TensorData::Float32(vec![1.2, 2.2, 3.2, 4.5]),
>     shape: vec![4],
> }));
> let prediction = muna.predictions.create(
>     "@fxn/identity",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Tensor(vector) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> > [!WARNING]
> >
> > Although Muna supports input vectors, compiled models will **always** output either scalars or `Tensor` instances--never plain vectors.
>
> Muna supports floating point tensors:
>
> ```ts JavaScript icon="js" theme={null}
> import type { Tensor } from "muna"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         matrix: {
>             data: new Float64Array([ 1.2, 2.2, 3.2, 4.5 ]),
>             shape: [2, 2]
>         } satisfies Tensor
>     }
> });
> const matrix = prediction.results[0] as Tensor;
> ```
>
> ```py Python icon="python" theme={null}
> import numpy as np
>
> prediction = muna.predictions.create(
>     tag="@fxn/identity",
>     inputs={
>         "matrix": np.array([ [1.2, 2.2], [3.2, 4.5] ], dtype="float64")
>     }
> )
> matrix: np.ndarray = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> import type { Tensor } from "@muna/expo"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         matrix: {
>             data: new Float64Array([ 1.2, 2.2, 3.2, 4.5 ]),
>             shape: [2, 2]
>         } satisfies Tensor
>     }
> });
> const matrix = prediction.results[0] as Tensor;
> ```
>
> ```kt Android icon="android" theme={null}
> import ai.muna.muna.types.Float64Tensor;
>
> val prediction = muna.predictions.create(
>     "@fxn/identity",
>     mapOf(
>         "matrix" to Float64Tensor(
>             doubleArrayOf(1.2, 2.2, 3.2, 4.5), // data
>             intArrayOf(2, 2) // shape
>         )
>     )
> );
> val matrix = (Float64Tensor)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/identity",
>     inputs: new () {
>         ["matrix"] = new Tensor<double>(
>             data: new [] { 1.2, 2.2, 3.2, 4.5 },
>             shape: new [] { 2, 2 }
>         )
>     }
> );
> var radius = (Tensor<double>)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> use muna::{Value, Tensor, TensorData};
>
> let mut inputs = HashMap::new();
> inputs.insert("matrix".to_string(), Value::Tensor(Tensor {
>     data: TensorData::Float64(vec![1.2, 2.2, 3.2, 4.5]),
>     shape: vec![2, 2],
> }));
> let prediction = muna.predictions.create(
>     "@fxn/identity",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Tensor(matrix) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```

> [accordion] Integer Values
>
> Muna supports several signed and unsigned integer scalars:
>
> | Muna value type | C/C++ type | Description |
> | :- | :- | :- |
> | `int8` | `int8_t` | Signed 8-bit integer. |
> | `int16` | `int16_t` | Signed 16-bit integer. |
> | `int32` | `int32_t` | Signed 32-bit integer. |
> | `int64` | `int64_t` | Signed 64-bit integer. |
> | `uint8` | `uint8_t` | Unsigned 8-bit integer. |
> | `uint16` | `uint16_t` | Unsigned 16-bit integer. |
> | `uint32` | `uint32_t` | Unsigned 32-bit integer. |
> | `uint64` | `uint64_t` | Unsigned 64-bit integer. |
>
> ```ts JavaScript icon="js" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/squeeze",
>     inputs: {
>         oranges: 12
>     }
> });
> const cups = prediction.results[0] as number;
> ```
>
> ```py Python icon="python" theme={null}
> prediction = muna.predictions.create(
>     tag="@fxn/squeeze",
>     inputs={
>         "oranges": 12
>     }
> )
> cups: int = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/squeeze",
>     inputs: {
>         oranges: 12
>     }
> });
> const cups = prediction.results[0] as number;
> ```
>
> ```kt Android icon="android" theme={null}
> val prediction = muna.predictions.create(
>     "@fxn/squeeze",
>     mapOf(
>         "oranges" to 12
>     )
> );
> val cups = (Int)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/squeeze",
>     inputs: new() {
>         ["oranges"] = 12
>     }
> );
> var cups = (int)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> let mut inputs = HashMap::new();
> inputs.insert("oranges".to_string(), 12i32.into());
> let prediction = muna.predictions.create(
>     "@fxn/squeeze",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Int(cups) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> > [!TIP]
> >
> > When integer scalars are passed to compiled models, the data type defaults to `int32`. Use
> > a tensor constructor to explicitly specify the data type.
>
> Muna supports integer vectors (i.e. one-dimensional integer tensors) of the aforementioned integer types:
>
> ```ts JavaScript icon="js" theme={null}
> import type { Tensor } from "muna"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         vector: new Int16Array([ 1, 2, 3, 4 ])
>     }
> });
> const vector = prediction.results[0] as Tensor;
> ```
>
> ```py Python icon="python" theme={null}
> import numpy as np
>
> prediction = muna.predictions.create(
>     tag="@fxn/identity",
>     inputs={
>         "vector": np.array([1, 2, 3, 4], dtype="int16")
>     }
> )
> vector: np.ndarray = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> import type { Tensor } from "@muna/expo"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         vector: new Int16Array([ 1, 2, 3, 4 ])
>     }
> });
> const vector = prediction.results[0] as Tensor;
> ```
>
> ```kt Android icon="android" theme={null}
> import ai.muna.muna.types.Int16Tensor;
>
> val prediction = muna.predictions.create(
>     "@fxn/identity",
>     mapOf(
>         "vector" to shortArrayOf(1, 2, 3, 4)
>     )
> );
> val vector = (Int16Tensor)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/identity",
>     inputs: new () {
>         ["vector"] = new short[] { 1, 2, 3, 4 }
>     }
> );
> var vector = (Tensor<short>)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> use muna::{Value, Tensor, TensorData};
>
> let mut inputs = HashMap::new();
> inputs.insert("vector".to_string(), Value::Tensor(Tensor {
>     data: TensorData::Int16(vec![1, 2, 3, 4]),
>     shape: vec![4],
> }));
> let prediction = muna.predictions.create(
>     "@fxn/identity",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Tensor(vector) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> > [!WARNING]
> >
> > Although Muna supports input vectors, compiled models will **always** output either scalars or `Tensor` instances--never plain vectors.
>
> Muna supports integer tensors:
>
> ```ts JavaScript icon="js" theme={null}
> import type { Tensor } from "muna"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/transpose",
>     inputs: {
>         matrix: {
>             data: new Int16Array([ 1, 2, 3, 4 ]),
>             shape: [2, 2]
>         } satisfies Tensor
>     }
> });
> const matrix = prediction.results[0] as Tensor;
> ```
>
> ```py Python icon="python" theme={null}
> import numpy as np
>
> prediction = muna.predictions.create(
>     tag="@fxn/transpose",
>     inputs={
>         "matrix": np.array([ [1, 2], [3, 4] ], dtype="int16")
>     }
> )
> matrix: np.ndarray = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> import type { Tensor } from "@muna/expo"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/transpose",
>     inputs: {
>         matrix: {
>             data: new Int16Array([ 1, 2, 3, 4 ]),
>             shape: [2, 2]
>         } satisfies Tensor
>     }
> });
> const matrix = prediction.results[0] as Tensor;
> ```
>
> ```kt Android icon="android" theme={null}
> import ai.muna.muna.types.Int16Tensor;
>
> val prediction = muna.predictions.create(
>     "@fxn/transpose",
>     mapOf(
>         "matrix" to Int16Tensor(
>             shortArrayOf(1, 2, 3, 4),
>             intArrayOf(2, 2)
>         )
>     )
> );
> val matrix = (Int16Tensor)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/transpose",
>     inputs: new() {
>         ["matrix"] = new Tensor<short>(
>             data: new [] { 1, 2, 3, 4 },
>             shape: new [] { 2, 2 }
>         )
>     }
> );
> var radius = (Tensor<short>)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> use muna::{Value, Tensor, TensorData};
>
> let mut inputs = HashMap::new();
> inputs.insert("matrix".to_string(), Value::Tensor(Tensor {
>     data: TensorData::Int16(vec![1, 2, 3, 4]),
>     shape: vec![2, 2],
> }));
> let prediction = muna.predictions.create(
>     "@fxn/transpose",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Tensor(matrix) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> > [!WARNING]
> >
> > Unsigned integer tensors are not supported in our Android client because of missing language support in Java.

> [accordion] Boolean Values
>
> Muna supports boolean scalars:
>
> ```ts JavaScript icon="js" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/negate",
>     inputs: {
>         value: true
>     }
> });
> const truthy = prediction.results[0] as boolean;
> ```
>
> ```py Python icon="python" theme={null}
> prediction = muna.predictions.create(
>     tag="@fxn/negate",
>     inputs={
>         "value": True
>     }
> )
> truthy: bool = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/negate",
>     inputs: {
>         value: true
>     }
> });
> const truthy = prediction.results[0] as boolean;
> ```
>
> ```kt Android icon="android" theme={null}
> val prediction = muna.predictions.create(
>     "@fxn/negate",
>     mapOf(
>         "value" to true
>     )
> );
> val truthy = (Boolean)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/negate",
>     inputs: new () {
>         ["value"] = true
>     }
> );
> var truthy = (bool)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> let mut inputs = HashMap::new();
> inputs.insert("value".to_string(), true.into());
> let prediction = muna.predictions.create(
>     "@fxn/negate",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Bool(truthy) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> Muna supports boolean vectors (i.e. one-dimensional boolean tensors):
>
> ```ts JavaScript icon="js" theme={null}
> import { BoolArray, type Tensor } from "muna"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         vector: new BoolArray([ true, true, false, true ])
>     }
> });
> const vector = prediction.results[0] as Tensor;
> ```
>
> ```py Python icon="python" theme={null}
> import numpy as np
>
> prediction = muna.predictions.create(
>     tag="@fxn/identity",
>     inputs={
>         "vector": np.array([True, True, False, True], dtype="bool")
>     }
> )
> vector: np.ndarray = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> import { BoolArray, type Tensor } from "@muna/expo"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         vector: new BoolArray([ true, true, false, true ])
>     }
> });
> const vector = prediction.results[0] as Tensor;
> ```
>
> ```kt Android icon="android" theme={null}
> import ai.muna.muna.types.BoolTensor;
>
> val prediction = muna.predictions.create(
>     "@fxn/identity",
>     mapOf(
>         "vector" to booleanArrayOf(true, true, false, true)
>     )
> );
> val vector = (BoolTensor)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/identity",
>     inputs: new () {
>         ["vector"] = new[] { true, true, false, true }
>     }
> );
> var vector = (Tensor<bool>)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> use muna::{Value, Tensor, TensorData};
>
> let mut inputs = HashMap::new();
> inputs.insert("vector".to_string(), Value::Tensor(Tensor {
>     data: TensorData::Bool(vec![true, true, false, true]),
>     shape: vec![4],
> }));
> let prediction = muna.predictions.create(
>     "@fxn/identity",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Tensor(vector) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> > [!WARNING]
> >
> > Although Muna supports input vectors, compiled models will **always** output either scalars or `Tensor` instances--never plain vectors.
>
> Muna supports boolean tensors:
>
> ```ts JavaScript icon="js" theme={null}
> import { BoolArray, type Tensor } from "muna"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/transpose",
>     inputs: {
>         matrix: {
>             data: new BoolArray([ true, true, false, true ]),
>             shape: [2, 2]
>         } satisfies Tensor
>     }
> });
> const matrix = prediction.results[0] as Tensor;
> ```
>
> ```py Python icon="python" theme={null}
> import numpy as np
>
> prediction = muna.predictions.create(
>     tag="@fxn/transpose",
>     inputs={
>         "matrix": np.array([ [True, True], [False, True] ], dtype="bool")
>     }
> )
> matrix: np.ndarray = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> import { BoolArray, type Tensor } from "@muna/expo"
>
> const prediction = await muna.predictions.create({
>     tag: "@fxn/transpose",
>     inputs: {
>         matrix: {
>             data: new BoolArray([ true, true, false, true ]),
>             shape: [2, 2]
>         } satisfies Tensor
>     }
> });
> const matrix = prediction.results[0] as Tensor;
> ```
>
> ```kt Android icon="android" theme={null}
> import ai.muna.muna.types.BoolTensor;
>
> val prediction = muna.predictions.create(
>     "@fxn/transpose",
>     mapOf(
>         "matrix" to BoolTensor(
>             booleanArrayOf(true, true, false, true),
>             intArrayOf(2, 2)
>         )
>     )
> );
> val matrix = (BoolTensor)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/transpose",
>     inputs: new () {
>         ["matrix"] = new Tensor<bool>(
>             data: new [] { true, true, false, true },
>             shape: new [] { 2, 2 }
>         )
>     }
> );
> var radius = (Tensor<bool>)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> use muna::{Value, Tensor, TensorData};
>
> let mut inputs = HashMap::new();
> inputs.insert("matrix".to_string(), Value::Tensor(Tensor {
>     data: TensorData::Bool(vec![true, true, false, true]),
>     shape: vec![2, 2],
> }));
> let prediction = muna.predictions.create(
>     "@fxn/transpose",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Tensor(matrix) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> > [!WARNING]
> >
> > Muna assumes that boolean values are 1 byte.

> [accordion] String Values
>
> Muna supports string values:
>
> ```ts JavaScript icon="js" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/upper",
>     inputs: {
>         text: "hello from function"
>     }
> });
> const uppercase = prediction.results[0] as string;
> ```
>
> ```py Python icon="python" theme={null}
> prediction = muna.predictions.create(
>     tag="@fxn/upper",
>     inputs={
>         "text": "hello from function"
>     }
> )
> uppercase: str = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/upper",
>     inputs: {
>         text: "hello from function"
>     }
> });
> const uppercase = prediction.results[0] as string;
> ```
>
> ```kt Android icon="android" theme={null}
> val prediction = muna.predictions.create(
>     "@fxn/upper",
>     mapOf(
>         "text" to "hello from function"
>     )
> );
> val uppercase = (String)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/upper",
>     inputs: new () {
>         ["text"] = "hello from function"
>     }
> );
> var uppercase = prediction.results[0] as string;
> ```
>
> ```rust Rust icon="rust" theme={null}
> let mut inputs = HashMap::new();
> inputs.insert("text".to_string(), "hello from function".into());
> let prediction = muna.predictions.create(
>     "@fxn/upper",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::String(uppercase) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```

> [accordion] List Values
>
> Muna supports lists of values, each with potentially different types:
>
> ```ts JavaScript icon="js" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         elements: ["hello", 10, false]
>     }
> });
> const elements = prediction.results[0] as any[];
> ```
>
> ```py Python icon="python" theme={null}
> from typing import Any, List
>
> prediction = muna.predictions.create(
>     tag="@fxn/identity",
>     inputs={
>         "elements": ["hello", 10, False]
>     }
> )
> elements: List[Any] = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         elements: ["hello", 10, false]
>     }
> });
> const elements = prediction.results[0] as any[];
> ```
>
> ```kt Android icon="android" theme={null}
> val prediction = muna.predictions.create(
>     "@fxn/identity",
>     mapOf(
>         "elements" to listOf("hello", 10, false)
>     )
> );
> val elements = (List<Any>)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> using Newtonsoft.Json.Linq;
>
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/identity",
>     inputs: new() {
>         ["elements"] = new object[] { "hello", 10, false } // can be any `T : IList`
>     }
> );
> var elements = prediction.results[0] as JArray;
> ```
>
> ```rust Rust icon="rust" theme={null}
> use muna::Value;
>
> let mut inputs = HashMap::new();
> inputs.insert("elements".to_string(), Value::List(vec![
>     serde_json::json!("hello"),
>     serde_json::json!(10),
>     serde_json::json!(false),
> ]));
> let prediction = muna.predictions.create(
>     "@fxn/identity",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::List(elements) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> > [!NOTE]
> >
> > Input list values **must** be JSON-serializable.

> [accordion] Dictionary Values
>
> Muna supports dictionary values:
>
> ```ts JavaScript icon="js" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         person: {
>             name: "Sara",
>             age: 27
>         }
>     }
> });
> const person = prediction.results[0] as Record<string, any>;
> ```
>
> ```py Python icon="python" theme={null}
> from typing import Any, Dict
>
> prediction = muna.predictions.create(
>     tag="@fxn/identity",
>     inputs={
>         "person": {
>             "name": "Sara",
>             "age": 27
>         }
>     }
> )
> person: Dict[str, Any] = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@fxn/identity",
>     inputs: {
>         person: {
>             name: "Sara",
>             age: 27
>         }
>     }
> });
> const person = prediction.results[0] as Record<string, any>;
> ```
>
> ```kt Android icon="android" theme={null}
> val prediction = muna.predictions.create(
>     "@fxn/identity",
>     mapOf(
>         "person" to mapOf(
>             "name" to "Sara",
>             "age" to 27
>         )
>     )
> );
> val person = (Map<String, Any>)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> using System.Collections.Generic;
> using Newtonsoft.Json.Linq;
>
> var prediction = await muna.Predictions.Create(
>     tag: "@fxn/identity",
>     inputs: new() {
>         ["person"] = new Dictionary<string, object> { // can be any `T : IDictionary`
>             ["name"] = "Sara",
>             ["age"] = 27
>         }
>     }
> );
> var person = prediction.results[0] as JObject;
> ```
>
> ```rust Rust icon="rust" theme={null}
> use muna::Value;
>
> let mut inputs = HashMap::new();
> let mut person = serde_json::Map::new();
> person.insert("name".to_string(), serde_json::json!("Sara"));
> person.insert("age".to_string(), serde_json::json!(27));
> inputs.insert("person".to_string(), Value::Dict(person));
> let prediction = muna.predictions.create(
>     "@fxn/identity",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Dict(person) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> > [!NOTE]
> >
> > Input dictionary values **must** be JSON-serializable.

> [accordion] Image Values
>
> Muna supports images, represented as raw pixel buffers with 8 bytes per pixel and interleaved by channel.
> Muna supports three pixel buffer formats:
>
> | Pixel format | Channels | Description |
> | :- | :- | :- |
> | `A8` | 1 | Single channel luminance or alpha image. |
> | `RGB888` | 3 | Color image without alpha channel. |
> | `RGBA8888` | 4 | Color image with alpha channel. |
>
> Some client SDKs provide `Image` utility types for working with images:
>
> ```ts JavaScript icon="js" theme={null}
> import type { Image } from "muna"
>
> const prediction = await muna.predictions.create({
>     tag: "@vision-co/remove-background",
>     inputs: {
>         image: {
>             data: new Uint8ClampedArray(1280 * 720 * 3),
>             width: 1280,
>             height: 720,
>             channels: 3
>         } satisfies Image
>     }
> });
> const image = prediction.results[0] as Image;
> ```
>
> ```py Python icon="python" theme={null}
> from PIL import Image
>
> prediction = muna.predictions.create(
>     tag="@vision-co/remove-background",
>     inputs={
>         "image": Image.open("cat.jpg")
>     }
> )
> image: Image.Image = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> import type { Image } from "@muna/expo"
>
> const prediction = await muna.predictions.create({
>     tag: "@vision-co/remove-background",
>     inputs: {
>         image: {
>             data: new Uint8ClampedArray(1280 * 720 * 3),
>             width: 1280,
>             height: 720,
>             channels: 3
>         } satisfies Image
>     }
> });
> const image = prediction.results[0] as Image;
> ```
>
> ```kt Android icon="android" theme={null}
> import ai.muna.muna.types.Image;
>
> val prediction = muna.predictions.create(
>     "@vision-co/remove-background",
>     mapOf(
>         "image" to Image(
>             ByteBuffer.allocateDirect(1280 * 720 * 3),
>             1280, // width
>             720,  // height
>             3     // channels
>         )
>     )
> );
> val image = (Image)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> var prediction = await muna.Predictions.Create(
>     tag: "@vision-co/remove-background",
>     inputs: new () {
>         ["image"] = new Image(
>             data: new byte[1280 * 720 * 3],
>             width: 1280,
>             height: 720,
>             channels: 3
>         )
>     }
> );
> var image = (Image)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> use muna::{Value, Image};
>
> let mut inputs = HashMap::new();
> inputs.insert("image".to_string(), Value::Image(Image {
>     data: vec![0u8; 1280 * 720 * 3],
>     width: 1280,
>     height: 720,
>     channels: 3,
> }));
> let prediction = muna.predictions.create(
>     "@vision-co/remove-background",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Image(image) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```

> [accordion] Binary Values
>
> Muna supports binary blobs:
>
> ```ts JavaScript icon="js" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@vision-co/decode-jpeg",
>     inputs: {
>         buffer: new ArrayBuffer(1024)
>     }
> });
> const buffer = prediction.results[0] as ArrayBuffer;
> ```
>
> ```py Python icon="python" theme={null}
> from io import BytesIO
>
> prediction = muna.predictions.create(
>     tag="@vision-co/decode-jpeg",
>     inputs={
>         "buffer": BytesIO(b"\x00\x01") # or `bytes`, `bytearray`, `memoryview`
>     }
> )
> buffer: BytesIO = prediction.results[0]
> ```
>
> ```ts React Native icon="react" theme={null}
> const prediction = await muna.predictions.create({
>     tag: "@vision-co/decode-jpeg",
>     inputs: {
>         buffer: new ArrayBuffer(1024)
>     }
> });
> const buffer = prediction.results[0] as ArrayBuffer;
> ```
>
> ```kt Android icon="android" theme={null}
> val prediction = muna.predictions.create(
>     "@vision-co/decode-png",
>     mapOf(
>         "buffer" to ByteArrayInputStream(byteArrayOf(0x1, 0x2)) // must be an `InputStream`
>     )
> );
> val buffer = (InputStream)prediction.results[0];
> ```
>
> ```csharp Unity icon="unity" theme={null}
> using System.IO;
>
> var prediction = await muna.Predictions.Create(
>     tag: "@vision-co/decode-jpeg",
>     inputs: new () {
>         ["buffer"] = new MemoryStream() // must be a `Stream`
>     }
> );
> var buffer = (Stream)prediction.results[0];
> ```
>
> ```rust Rust icon="rust" theme={null}
> use muna::Value;
>
> let mut inputs = HashMap::new();
> inputs.insert("buffer".to_string(), Value::Binary(vec![0x00, 0x01]));
> let prediction = muna.predictions.create(
>     "@vision-co/decode-jpeg",
>     Some(inputs),
>     None,
>     None,
>     None,
>     None,
> ).await.unwrap();
> let Value::Binary(buffer) = &prediction.results.unwrap()[0] else { unreachable!() };
> ```
>
> > [!NOTE]
> >
> > Because Muna's [security model](https://docs.muna.ai/security.md) prohibits file system access, binary input values
> > are always fully read into memory before being passed to the compiled model.
> >
> > To run inference on large files, consider mapping the file into memory
> > using [`mmap`](https://linux.die.net/man/2/mmap) or your environment's equivalent.

## Specifying Inference Acceleration

Muna lets you choose which processor runs inference on the local device, per-request. Specify an `acceleration` when creating or streaming a prediction:

```ts JavaScript icon="js" focus={1,5} theme={null}
// 🔥 Run inference with the local NPU
const prediction = await muna.predictions.create({
  tag: "@bytedance/depth-anything-3",
  inputs: { image },
  acceleration: "local_npu"
});
```

```py Python icon="python" focus={1,5} theme={null}
# 🔥 Run inference with the local NPU
prediction = muna.predictions.create(
  tag="@bytedance/depth-anything-3",
  inputs={ "image": image },
  acceleration="local_npu"
)
```

```ts React Native icon="react" focus={1,5} theme={null}
// 🔥 Run inference with the local NPU
const prediction = await muna.predictions.create({
  tag: "@bytedance/depth-anything-3",
  inputs: { image },
  acceleration: "local_npu"
});
```

```swift iOS icon="swift" focus={1,5} theme={null}
// 🔥 Run inference with the Apple Neural Engine
let prediction = try await muna.predictions.create(
  tag: "@bytedance/depth-anything-3",
  inputs: ["image": image],
  acceleration: .npu
)
```

```kt Android icon="android" focus={1,5} theme={null}
// 🔥 Run inference with the local NPU
val prediction = muna.predictions.create(
  "@bytedance/depth-anything-3",
  mapOf("image" to image),
  Acceleration.NPU
)
```

```csharp Unity icon="unity" focus={1,5} theme={null}
// 🔥 Run inference with the local NPU
var prediction = await muna.Predictions.Create(
  tag: "@bytedance/depth-anything-3",
  inputs: new() { ["image"] = image },
  acceleration: @"local_npu"
);
```

### Specifying the Acceleration

Below are the currently supported acceleration specifiers:

| Acceleration | Notes |
| :- | :- |
| `local_cpu` | Use the CPU to accelerate inference. |
| `local_gpu` | Use the GPU to accelerate inference. |
| `local_npu` | Use the neural processor to accelerate inference. |

### Specifying the Devices

Some Muna clients allow you to specify the acceleration devices used to run inference. Pass a list of `devices` when creating or streaming a prediction:

```py Python icon="python" focus={1,2,6} theme={null}
# 🔥 Run inference on GPUs 4 through 7
from muna import Device

prediction = muna.predictions.create(
  tag="@deepseek-ai/deepseek-v4.1-flash",
  inputs={ "messages": messages },
  devices=[Device.cuda(4), Device.cuda(5), "cuda:6", "cuda:7"]
)
```

```rust Rust icon="rust" focus={1,2,8} theme={null}
// 🔥 Run inference on GPUs 4 through 7
use muna::Device;

let devices = [Device::cuda(4), Device::cuda(5), "cuda:6".parse()?, "cuda:7".parse()?];
let prediction = muna.predictions.create(
    "@deepseek-ai/deepseek-v4.1-flash",
    Some(inputs),
    None,
    Some(&devices),
    None,
    None,
).await?;
```

Devices are used in order. A model that runs across multiple GPUs takes the first devices it needs (e.g. a model that runs on 4 GPUs takes the first 4 devices), and ignores the rest. Predictor creation fails if you specify fewer devices than the model needs. When you specify no devices, the model uses its default devices.

> [!NOTE]
>
> Devices only take effect when the predictor is first loaded. To run a model on different devices, delete the predictor with `muna.predictions.delete(tag)`, then create a prediction with the new devices. Remote predictions ignore devices.

Each device is an opaque pointer. Use `Device.cuda(index)` in Python or `Device::cuda(index)` in Rust to create a CUDA device, or wrap a raw pointer with `Device(pointer)` in Python or `Device::from_pointer(pointer)` in Rust. The underlying type of the pointer depends on the current operating system:

> [accordion] Android
>
> Currently unsupported.

> [accordion] iOS
>
> Each device is reinterpreted as a [Metal device](https://developer.apple.com/documentation/metal/mtldevice?language=objc) with type `id<MTLDevice>`.

> [accordion] Linux
>
> Each device is reinterpreted as a pointer to a [CUDA device ID](https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__DEVICE.html) or [HIP device ID](https://rocm.docs.amd.com/projects/HIP/en/latest/reference/hip_runtime_api/modules/device_management.html#group___device_1ga43c1e7f15925eeb762195ccb5e063eae) with type `int*`.

> [accordion] macOS
>
> Each device is reinterpreted as a [Metal device](https://developer.apple.com/documentation/metal/mtldevice?language=objc) with type `id<MTLDevice>`.

> [accordion] Web
>
> Each device is reinterpreted as a [WebGPU device](https://developer.mozilla.org/en-US/docs/Web/API/GPUDevice) with type `GPUDevice`.

> [accordion] Windows
>
> Each device is reinterpreted as a [DirectX 12 device](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nn-d3d12-id3d12device) with type `ID3D12Device*`.

> [!CAUTION]
>
> You should never specify the inference device unless you know what the hell you're doing.

> [!NOTE]
>
> The inference `devices` are merely a hint. Setting `devices` does not guarantee that all
> or any operation in the compiled function will actually use those acceleration devices.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.