> ## 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.models.clients.dispatch

Shared helpers for concurrent per-tile dispatch failure handling.

These utilities are transport-agnostic and shared by every code path that fans a batch of tile requests out concurrently (the whole-slide inference pipeline and the standalone PyTorch adapter). They centralize how a batch summarizes and surfaces the tiles that failed after their per-request retry budget was exhausted, so the failure policy stays consistent and is defined in exactly one place.

***

#### summarize\_indices

```python theme={null}
def summarize_indices(indices: list[int],
                      limit: int = MAX_LOGGED_INDICES) -> str
```

Formats a possibly-long list of tile indices for error messages.

<ParamField body="indices">
  The tile indices to format.
</ParamField>

<ParamField body="limit">
  Maximum number of indices to list before truncating.
</ParamField>

**Returns**:

A comma-separated string, truncated with a count if too long.

***

#### dispatch\_failure\_error

```python theme={null}
def dispatch_failure_error(failures: list[tuple[int, BaseException]],
                           total_tiles: int,
                           *,
                           action: str = "Dispatch",
                           detail: str | None = None) -> BioptimusRuntimeError
```

Builds a typed error summarizing per-tile dispatch failures.

Constructs (but does not raise) a `BioptimusRuntimeError` tagged with `DISPATCH_FAILED`, chaining the lowest-indexed failure as the cause. Callers raise the returned error with `raise dispatch_failure_error(...) from ...` or simply `raise`; the cause is already attached.

<ParamField body="failures">
  `(tile_index, exception)` pairs for each failed tile.
</ParamField>

<ParamField body="total_tiles">
  Total number of tiles in the batch.
</ParamField>

<ParamField body="action">
  Verb describing the operation for the message, for example `"Dispatch"` or `"Prediction"`.
</ParamField>

<ParamField body="detail">
  Optional extra clause inserted before the first error, for example `"No output written."`.
</ParamField>

**Returns**:

The constructed error, with the first failure set as its cause.
