API Reference / cli /

serve.py

Serve Command - Start a REST API server for model predictions.

Functions

Command

tuiml serve

Line 46
tuiml serve [OPTIONS]

Serve a trained model over a REST API.

Loads a model and runs it behind HTTP endpoints in the foreground, so other services can request predictions over the network. The server is backed by serving and publishes interactive OpenAPI docs at /docs. Press Ctrl-C to shut it down, or stop a detached server with tuiml stop-server.

Serve a model on the default port:

bash
$ tuiml serve --model-path model.pkl

Serve on a custom port with a specific model ID:

bash
$ tuiml serve --model-path classifier.pkl -m my_classifier -p 9000

Serve with multiple workers, reachable from other machines:

bash
$ tuiml serve --model-path model.pkl -w 4 -H 0.0.0.0

Serve a model already trained in this session, by ID:

bash
$ tuiml serve --model-id abc123

Endpoints

  • GET /health - Health check
  • GET /stats - Server statistics
  • GET /models - List loaded models
  • POST /models - Load additional models
  • GET /models/{id} - Get model info
  • POST /models/{id}/predict - Make predictions
  • POST /models/{id}/predict_proba - Get probabilities
  • POST /predict - Predict with default model

API Documentation

After starting the server, visit:
  • http://localhost:8000/docs - Swagger UI
  • http://localhost:8000/redoc - ReDoc

Authentication

Every endpoint except / and /health needs a bearer token, printed on startup. Loading a model unpickles a file and predicting runs it, so the server does not expose either without one.

$ curl -H "Authorization: Bearer $TOKEN" localhost:8000/health

Options

--model-path
path
Path to a saved model file to serve (alternative to --model-id).
--model-id, -m
ID of a model already trained by "tuiml train". Also names the model in the URL path.
--host, -H
= '127.0.0.1'
Interface to bind to (default: 127.0.0.1). Use 0.0.0.0 to accept connections from other machines.
--port, -p
int = 8000
TCP port to listen on (default: 8000).
--workers, -w
int = 1
Number of worker processes to run (default: 1). Raise this to serve concurrent requests.
--reload
flag
Restart the server whenever the source changes. For development only.
--auth-token
Bearer token clients must send. Generated and printed if omitted.
--no-auth
flag
Serve without authentication. Only safe behind a proxy that authenticates for you.
--models-dir
path
Directory that POST /models may load from. Omitted, that endpoint is refused.