---
title: "TypeNN API reference"
description: "A practical index of TypeNN Device, Tensor, Module, optimizer, and autograd APIs."
url: https://nn.typeshade.dev/api/
language: en
---

Reference

# API reference

An index of the public API used in current examples. See the source declarations for exact overloads and options.

## Device and Tensor lifecycle

Create, execute, dispose device.ts

```ts
const device = await nn.device({ device: "auto" });
const x = device.tensor([1, 2, 3, 4], { shape: [2, 2] });
const y = x.relu().softmax();
const values = await y.data();

await y.disposeGraph();
await device.dispose();
```

- `device(options?)` Open a Device using auto, cpu, webgpu, or webgl2 selection.
- `Device.tensor(values, { shape })` Create an input tensor with a checked shape.
- `Tensor.data()` Materialize the requested graph result and return host values.
- `Tensor.disposeGraph(preserve?)` Release graph tensors while retaining selected values.
- `Device.dispose()` Wait for pending work and release runtime resources.

## Tensor operations

### Linear algebra

`matmul(other, options?)`
Rank-2 matrix multiply with transpose options.

### Elementwise

`add`, `sub`, `mul`, `div`, `maximum`, `minimum`, `pow`, and supported activations.

### Reduction and normalization

`sum`, `mean`, `max`, `min`, `argMax`, `softmax`, and `logSoftmax`.

### Loss and gradients

`softmaxCrossEntropyWithLogits`, `backward()`, and selected Tensor graph gradient rules.

## Modules and optimizers

- `Module` Register child layers, expose parameters, switch train/eval mode.
- `Sequential`, `Linear`, `Flatten`, `ReLU`, `Dropout` Core building blocks shown by current examples.
- `optim.SGD`, `optim.Adam` Compute gradients and update parameters in one device plan. Use `alsoRead` to read additional Tensors in the same plan.
- `CrossEntropyLoss` Loss module for logits and integer class labels in the MNIST example.

TypeShade's pure-function `shadeGrad` is separate from TypeNN Tensor graph autograd.

[Browse source declarations ↗](https://github.com/typeshade/typenn/tree/main/src)
