Local HTTP Model Serving
Serve any .dit model over HTTP with GET /health and POST /predict using ochreml serve and zero external web frameworks.
ochreml serve loads a .dit model once into memory and exposes a lightweight JSON HTTP server built entirely on Python's standard library (http.server.HTTPServer) — no FastAPI, Flask, or Uvicorn required (^▽^).
Start the Server
ochreml serve models/ridge.dit --host 127.0.0.1 --port 8080 --device autoStartup banner:
OchreML serving Ridge from models/ridge.dit at http://127.0.0.1:8080 (^▽^)Options:
model(positional): Path to a.ditmodel file.--host: Bind address (default:127.0.0.1).--port: Bind port (default:8080).--device: Target device for inference (auto,cpu,cuda:0,wgpu,tpu; default:auto).
Press Ctrl+C to shut down cleanly.
Endpoints
GET /health
Returns server liveness, loaded model class, model path, and OchreML version.
curl -s http://127.0.0.1:8080/healthResponse (200 OK):
{
"status": "ok",
"model_type": "Ridge",
"model_path": "models/ridge.dit",
"version": "0.3.7a1"
}POST /predict
Runs batch inference on a JSON payload containing a non-empty 2D list of numeric feature rows under either "inputs" or "X".
Using "inputs":
curl -s -X POST http://127.0.0.1:8080/predict \
-H "Content-Type: application/json" \
-d '{"inputs": [[5.1, 3.5, 1.4, 0.2], [6.2, 3.4, 5.4, 2.3]]}'Using "X" (also accepted):
curl -s -X POST http://127.0.0.1:8080/predict \
-H "Content-Type: application/json" \
-d '{"X": [[5.1, 3.5, 1.4, 0.2]]}'Response (200 OK):
{
"predictions": [0.0, 2.0],
"model_type": "Ridge"
}For multi-output neural network models (nn.Sequential classifiers emitting per-class logits), POST /predict automatically applies argmax per row to return predicted class indices.
Error Responses
| Status Code | Condition | Response Body |
|---|---|---|
400 Bad Request | Malformed JSON, missing/empty "inputs" or "X", or feature dimension mismatch | {"error": "<message>"} |
404 Not Found | Any path other than GET /health or POST /predict | {"error": "Not found"} |
Request Logging
By default, ochreml serve keeps stdout and stderr silent after startup. To enable per-request access logs on stderr, set OCHREML_DEBUG=1:
OCHREML_DEBUG=1 ochreml serve models/ridge.dit --port 8080Deployment Notes
ochreml serve uses Python's single-threaded stdlib HTTPServer. It is ideal for local development, edge/container prototypes, CI smoke tests, and internal microservices behind a reverse proxy. For high-concurrency production traffic, run multiple worker replicas behind a load balancer or embed ochreml.load() in your ASGI/WSGI server.