|
| 1 | +<!--- |
| 2 | +# ================================= |
| 3 | +# Copyright: CEA-LIST/DIASI/SIALV |
| 4 | +# Author : pixano@cea.fr |
| 5 | +# License: CECILL-C |
| 6 | +# ================================= |
| 7 | +---> |
| 8 | + |
| 9 | +# Pixano Inference HTTP API |
| 10 | + |
| 11 | +This document describes the HTTP API exposed by the Ray Serve-based Pixano |
| 12 | +Inference server. |
| 13 | + |
| 14 | +**Base URL:** `http://<host>:<port>` with default `http://127.0.0.1:7463` |
| 15 | + |
| 16 | +Start the server with a Python config file: |
| 17 | + |
| 18 | +```bash |
| 19 | +pixano-inference --config models.py |
| 20 | +``` |
| 21 | + |
| 22 | +## Overview |
| 23 | + |
| 24 | +- Models are loaded at startup from a Python `.py` config file passed to `--config`. |
| 25 | +- All inference routes are synchronous `POST` endpoints. |
| 26 | +- There are no runtime HTTP endpoints for deploying or undeploying models. |
| 27 | +- Every inference request includes a `model` field that must match a deployed model name. |
| 28 | +- Endpoint families are capability-based: segmentation, detection, tracking, and VLM. |
| 29 | + |
| 30 | +## Service endpoints |
| 31 | + |
| 32 | +| Method | Path | Purpose | |
| 33 | +| ------ | ---------------- | ------------------------------------ | |
| 34 | +| `GET` | `/` | Basic API metadata and docs link | |
| 35 | +| `GET` | `/health` | Liveness probe | |
| 36 | +| `GET` | `/ready` | Readiness summary | |
| 37 | +| `GET` | `/app/settings/` | Server settings and resource summary | |
| 38 | +| `GET` | `/app/models/` | List deployed models | |
| 39 | + |
| 40 | +### `GET /app/settings/` |
| 41 | + |
| 42 | +Example response: |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "app_name": "Pixano Inference", |
| 47 | + "app_version": "0.6.0", |
| 48 | + "app_description": "Pixano Inference API powered by Ray Serve", |
| 49 | + "num_cpus": 8, |
| 50 | + "num_gpus": 2, |
| 51 | + "num_nodes": 1, |
| 52 | + "gpus_used": 1.0, |
| 53 | + "gpu_to_model": {}, |
| 54 | + "models": ["sam2-image"], |
| 55 | + "models_to_capability": { |
| 56 | + "sam2-image": "segmentation" |
| 57 | + } |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +### `GET /app/models/` |
| 62 | + |
| 63 | +Returns a list of `ModelInfo` objects: |
| 64 | + |
| 65 | +```json |
| 66 | +[ |
| 67 | + { |
| 68 | + "name": "sam2-image", |
| 69 | + "capability": "segmentation", |
| 70 | + "model_path": "facebook/sam2-hiera-base-plus", |
| 71 | + "model_class": "Sam2ImageModel" |
| 72 | + } |
| 73 | +] |
| 74 | +``` |
| 75 | + |
| 76 | +## Inference endpoints |
| 77 | + |
| 78 | +| Method | Path | Request schema | Response schema | Python client helper | |
| 79 | +| ------ | -------------------------- | --------------------- | ---------------------- | ----------------------- | |
| 80 | +| `POST` | `/inference/segmentation/` | `SegmentationRequest` | `SegmentationResponse` | `client.segmentation()` | |
| 81 | +| `POST` | `/inference/detection/` | `DetectionRequest` | `DetectionResponse` | `client.detection()` | |
| 82 | +| `POST` | `/inference/tracking/` | `TrackingRequest` | `TrackingResponse` | `client.tracking()` | |
| 83 | +| `POST` | `/inference/vlm/` | `VLMRequest` | `VLMResponse` | `client.vlm()` | |
| 84 | + |
| 85 | +If a model exists but does not support the endpoint capability, the server |
| 86 | +returns `400`. |
| 87 | + |
| 88 | +The request and response models are available from `pixano_inference.schemas`. |
| 89 | + |
| 90 | +### Example: segmentation |
| 91 | + |
| 92 | +```json |
| 93 | +{ |
| 94 | + "model": "sam2-image", |
| 95 | + "image": "data:image/png;base64,...", |
| 96 | + "points": [[[200, 175]]], |
| 97 | + "labels": [[1]] |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +### Example: detection |
| 102 | + |
| 103 | +```json |
| 104 | +{ |
| 105 | + "model": "grounding-dino", |
| 106 | + "image": "http://images.cocodataset.org/val2017/000000039769.jpg", |
| 107 | + "classes": ["cat", "remote control"], |
| 108 | + "box_threshold": 0.3, |
| 109 | + "text_threshold": 0.2 |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +## Response envelope |
| 114 | + |
| 115 | +All inference endpoints return the same top-level envelope: |
| 116 | + |
| 117 | +```json |
| 118 | +{ |
| 119 | + "id": "ray-sam2-image-1739000000000", |
| 120 | + "status": "SUCCESS", |
| 121 | + "timestamp": "2026-01-01T12:00:00", |
| 122 | + "processing_time": 0.234, |
| 123 | + "metadata": { |
| 124 | + "model_name": "sam2-image", |
| 125 | + "capability": "segmentation", |
| 126 | + "model_class": "Sam2ImageModel" |
| 127 | + }, |
| 128 | + "data": {} |
| 129 | +} |
| 130 | +``` |
| 131 | + |
| 132 | +| Field | Description | |
| 133 | +| ----------------- | ---------------------------------------------------------- | |
| 134 | +| `id` | Server-generated request identifier | |
| 135 | +| `status` | Inference status, typically `SUCCESS` | |
| 136 | +| `timestamp` | Response timestamp | |
| 137 | +| `processing_time` | End-to-end inference time in seconds | |
| 138 | +| `metadata` | Deployment metadata for the model that handled the request | |
| 139 | +| `data` | Capability-specific payload | |
| 140 | + |
| 141 | +## Python client |
| 142 | + |
| 143 | +```python |
| 144 | +import asyncio |
| 145 | + |
| 146 | +from pixano_inference.client import PixanoInferenceClient |
| 147 | +from pixano_inference.schemas import SegmentationRequest |
| 148 | + |
| 149 | + |
| 150 | +async def main() -> None: |
| 151 | + client = PixanoInferenceClient.connect("http://localhost:7463") |
| 152 | + request = SegmentationRequest( |
| 153 | + model="sam2-image", |
| 154 | + image="data:image/png;base64,...", |
| 155 | + points=[[[200, 175]]], |
| 156 | + labels=[[1]], |
| 157 | + ) |
| 158 | + response = await client.segmentation(request) |
| 159 | + print(response.processing_time) |
| 160 | + print(response.data.scores.to_numpy()) |
| 161 | + |
| 162 | + |
| 163 | +asyncio.run(main()) |
| 164 | +``` |
| 165 | + |
| 166 | +## Error responses |
| 167 | + |
| 168 | +- `400` when the model exists but does not support the requested capability. |
| 169 | +- `404` when the requested model name is not deployed. |
| 170 | +- `422` when the request body fails schema validation. |
| 171 | +- `500` when inference fails inside the model deployment. |
| 172 | + |
| 173 | +The Python client raises `fastapi.HTTPException` with the server error detail |
| 174 | +when a request is unsuccessful. |
0 commit comments