Skip to main content
HTTP client for direct API endpoints. Sends JSON payloads to a model server via plain HTTP POST using requests (synchronous) and aiohttp (asynchronous).

is_transient

Returns whether an exception is a transient failure worth retrying. Transient failures include connection resets, timeouts, and HTTP responses carrying a retryable server-side status code (e.g. 503 from momentary GPU back-pressure). Deterministic failures such as HTTP 400 (malformed request) are not retried.
The exception raised while dispatching a request.
Returns: True if the failure is transient and should be retried.

tile_retry_logger

Builds an on_retry callback that logs a per-tile dispatch retry. Returns the callback expected by retry_sync / retry_async, emitting a structured tile_dispatch_retry warning. Shared by every per-tile dispatch path so the retry log event and fields stay identical.
The logger to emit on.
Index of the tile being retried, recorded in the event.
Retry budget, used to report the total attempt count.
Returns: A callback taking (attempt, exc, delay) that logs the retry.

retry_sync

Runs attempt, retrying transient failures with exponential backoff. Synchronous twin of retry_async for threaded (non-async) callers, such as the TorchModel thread-pool dispatch. Shares the same backoff policy, defaults, and on_retry contract so both paths behave identically.
Zero-argument callable that performs one attempt.
Number of retries after the initial attempt (so the total number of attempts is max_retries + 1).
Seed for the exponential backoff (base_delay * 2**n).
Predicate deciding whether a raised exception is transient and worth retrying.
Blocking sleep function; injectable so tests can skip real waits.
Optional callback invoked before each retry with the zero-based attempt number, the exception, and the delay.
Returns: The result of the first successful attempt. Raises:
  • BaseException - Re-raises the last exception when the retry budget is exhausted or the exception is not retryable.

retry_async

Runs attempt, retrying transient failures with exponential backoff. The retry mechanism is transport-agnostic: the work to perform, the logging, and (optionally) the sleep function are all supplied by the caller, keeping this function reusable and easy to test.
Zero-argument coroutine factory that performs one attempt.
Number of retries after the initial attempt (so the total number of attempts is max_retries + 1).
Seed for the exponential backoff (base_delay * 2**n).
Predicate deciding whether a raised exception is transient and worth retrying.
Async sleep function; injectable so tests can skip real waits.
Optional callback invoked before each retry with the zero-based attempt number, the exception, and the delay.
Returns: The result of the first successful attempt. Raises:
  • BaseException - Re-raises the last exception when the retry budget is exhausted or the exception is not retryable.

HTTPClient

Sends JSON payloads over HTTP. Fully configured at construction — predict / embed only need the serialized body.
Root URL of the model server, e.g. "http://localhost:8080".
Mapping of endpoint type to path. At least one key must be present; see the example below.
HTTP request timeout in seconds.
Example:

close

Closes the underlying HTTP session and releases connections.

predict

POST to the prediction endpoint.
Serialized JSON request payload.
Returns: Response body as a JSON string.

embed

POST to the embedding endpoint.
Serialized JSON request payload.
Returns: Response body as a JSON string.

predict_with_embedding

POST to the combined prediction+embedding endpoint. Returns both the gene prediction and the tile embedding from a single forward pass. Only models that expose both prediction and embedding configure this endpoint; others raise NotImplementedError.
Serialized JSON request payload.
Returns: Response body as a JSON string, with embedding populated alongside output.

metadata

GET the metadata endpoint. Returns: Response body as a JSON string.

predict_async

POST to the prediction endpoint asynchronously.
Serialized JSON request payload.
An aiohttp.ClientSession for connection pooling.
Returns: Response body as a JSON string.

embed_async

POST to the embedding endpoint asynchronously.
Serialized JSON request payload.
An aiohttp.ClientSession for connection pooling.
Returns: Response body as a JSON string.

predict_with_embedding_async

POST to the combined prediction+embedding endpoint asynchronously.
Serialized JSON request payload.
An aiohttp.ClientSession for connection pooling.
Returns: Response body as a JSON string, with embedding populated alongside output.