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

# bioptimus.inference.schemas

Request and response schemas for model inference.

These Pydantic models define the JSON payloads exchanged between clients and a deployed model endpoint (e.g. SageMaker or a local server). Each request/response pair corresponds to a single tile.

## OutputSchema

```python theme={null}
class OutputSchema(enum.StrEnum)
```

Single source of truth for tile-output array and attribute names.

The whole-slide inference pipeline persists per-tile results to Zarr, HDF5, and NPZ files (see `bioptimus.inference.writers`) and later reads them back for slide-level aggregation (see `bioptimus.inference.aggregate`). The on-disk array/attribute names form a contract binding the writer to the reader: if a writer name changed without the reader following, the reader would silently break.

These names are defined here once and referenced by both sides so the contract has a single source of truth. Changing a value here changes the on-disk format, so treat these as stable identifiers, not free-form labels. Because it is a `StrEnum`, members compare, hash, and serialize exactly like their string value, so they are drop-in wherever an array or attribute name string was used.

## InferenceMode

```python theme={null}
class InferenceMode(enum.StrEnum)
```

Inference modes shared across the server, clients, and pipeline.

The values are the on-wire strings (the SageMaker `/invocations` `mode` field and the REST endpoint keys), so this enum is the single source of truth for mode identifiers without changing the wire contract. Because it is a `StrEnum`, members compare, hash, and serialize exactly like their string value, so they are drop-in wherever a mode string was used.

***

#### coerce\_inference\_mode

```python theme={null}
def coerce_inference_mode(value: InferenceMode | str) -> InferenceMode
```

Normalizes a mode or stage argument to an [`InferenceMode`](https://docs.bioptimus.com/sdk-reference/inference/schemas#inferencemode).

Accepts an [`InferenceMode`](https://docs.bioptimus.com/sdk-reference/inference/schemas#inferencemode) member unchanged, a canonical on-wire string (for example `"prediction"`), or a legacy short spelling (for example `"predict"`). A legacy spelling is translated to its canonical member and emits a `DeprecationWarning`, so the enum is the single source of truth while pre-enum callers keep working.

**value**

The mode or stage to normalize.

**Returns**:

The corresponding [`InferenceMode`](https://docs.bioptimus.com/sdk-reference/inference/schemas#inferencemode) member.

**Raises**:

* `BioptimusValueError` - If `value` is neither a member, a canonical value, nor a known legacy spelling.

## ModelRequest

```python theme={null}
class ModelRequest(BaseModel)
```

Payload sent to the model endpoint for a single tile.

The tile image is base64-encoded for JSON transport. Bulk RNA counts can optionally be included for multimodal models.

**Attributes**:

* `image_data` - Base64-encoded tile image (PNG).
* `bulk_rna` - Optional bulk RNA counts vector.
* `slide_name` - Stem of the source slide filename.
* `x` - Tile x-coordinate in the slide.
* `y` - Tile y-coordinate in the slide.
* `width` - Tile width in pixels.
* `height` - Tile height in pixels.
* `tissue_ratio` - Fraction of tissue in the tile.
* `patch_idx` - Index of this tile in the extraction plan.

***

#### image

```python theme={null}
@property
def image() -> Image.Image
```

Decodes and returns the tile image as PIL.

## ModelResponse

```python theme={null}
class ModelResponse(BaseModel)
```

Payload returned by the model endpoint for a single tile.

Carries the model output together with the full tile metadata from the originating request, so that downstream writers can persist everything without needing a separate schema.

**Attributes**:

* `output` - Model output vector for this tile.
* `slide_name` - Stem of the source slide filename.
* `x` - Tile x-coordinate in the slide.
* `y` - Tile y-coordinate in the slide.
* `width` - Tile width in pixels.
* `height` - Tile height in pixels.
* `tissue_ratio` - Fraction of tissue in the tile.
* `patch_idx` - Index of this tile in the extraction plan.
* `resolution` - Extraction resolution (MPP) if available.
* `embedding` - The tile embedding, returned alongside `output` only for the `prediction_with_embedding` mode (both come from the same forward pass). `None` for the single-output modes.

## SageMakerRequest

```python theme={null}
class SageMakerRequest(ModelRequest)
```

Extended request for the SageMaker `/invocations` endpoint.

Adds a `model_name` field so the server can dispatch to the correct model and a `mode` field to select the scheduler (see [`InferenceMode`](https://docs.bioptimus.com/sdk-reference/inference/schemas#inferencemode)).


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