Serving a model, and taking it elsewhere
Call a model over HTTP from this machine, choose an alias or a pinned version, and pick the export that fits where the model has to run.
You will be able to
- Decide when a decision needs real-time scoring and when a batch will do
- Create a local endpoint and call it with a bearer token
- Keep the threshold decision separate from the score an endpoint returns
- Choose an export for the place the model has to run
Does this decision need an answer now?
PredictPredict first
You have two uses for a model: a list of likely churners that a team reviews every Monday, and a fraud check that has to answer before a payment completes. What does each one need?
Reveal
Batch for the list, real time for the payment. A serving endpointServing endpointA URL that takes rows and returns predictions immediately, for decisions that can't wait for a batch. is worth its extra moving parts only when the decision can't wait. Start from batch, and move to serving when you can name the decision that needs it.
The local server
ReadThe app can serve registered models on your own machine, for scripts and apps that run there. It listens on 127.0.0.1 only, on port 8790 by default, and every scoring call needs a bearer token kept in your OS keychain.
| Route | What it does |
|---|---|
GET /v1/health | Is the server up? No token needed |
GET /v1/models | The enabled endpoints and their input signatures |
POST /v1/models/<name>:predict | Takes rows, returns predictions |
It isn't a production host. When other machines need the model, use an export.
Make an endpoint
In the appOpen a version's Monitor & serve tab and scroll to Serving.
- Press Start the server. It stays on at the next launch until you stop it.
- Press New endpoint, and choose what it serves and which scorer it uses.
- Press Try it. The request comes filled in with an example, and Send runs the same path as a real call.
- Press Copy curl to take the request to a terminal.
Rows sent to an endpoint go through the same signature check as a batch.
Alias or pinned?
ReadAn endpoint can follow an alias or stay on one version. If it follows champion, promoting or rolling back changes what callers get, with no change on their side. A pinned version stays put, which suits a downstream system that has to validate each model first.
The scorer matters too. SQL answers in milliseconds, but only for linear models and single trees. The training engine handles any model, with a kernel run for each request.
A score isn't a decision
ExploreAn endpoint returns predictions and class probabilities. What you do with them is a separate choice, and it's yours.
HExplorable · The ROC curve and its threshold
What does moving a threshold trade away, and what does the AUC really measure?
How often does a random positive score above a random negative?
Commit your prediction above to see the result
Make your prediction to see the result.
Move the threshold, and watch what you trade. Then try a rare condition: the same model and the same AUC, but most flagged cases are now false alarms.
The right cut depends on how common the event is and what each mistake costs. Both can change while the model stays the same, so keep the threshold in the calling system, where you can change it.
Taking it elsewhere
ReadThe Export tab packages a version for other places:
| Export | Use it when |
|---|---|
| Native files | You want the model, preprocessing and manifest as they are |
| ONNX | You need a language-neutral graph; the app checks it against native predictions and shows the largest difference |
| ONNX (torch) | A neural network from Python or R must run without either |
| Python or R scoring script | A scheduled job elsewhere will score tables |
| DuckDB SQL | A linear model or single tree should run with no Python or R |
| MLflow model | Your team already serves models with MLflow |
From Serving, you can also export a runnable FastAPI or plumber app with a Dockerfile. It returns predictions and probabilities only, without the SD, interval or set the local server can add.
Choose for your team
ReflectThink about where a model of yours would have to run.
Who owns that system? Can it run Python or R? Does it need a person to approve each new version, or should it follow the champion?
Write down your answers before you pick an export. The choice usually depends more on who maintains it than on the model.
Check your understanding
CheckpointCheck yourself
A colleague on another machine wants to call your local endpoint. What should you do?
Show the answer
Answer: b
The local server only accepts requests addressed to this machine, by design. Exports are how a model leaves it.
Check yourself
Your endpoint follows champion. You roll back by pointing champion at the previous version. What must callers change?
Show the answer
Answer: a
Callers use the endpoint's name. The alias decides which version answers, so moving it is the whole rollback.
Check yourself
Fraud becomes twice as common, while the model ranks cases as well as before. What needs another look?
Show the answer
Answer: a
AUC doesn't depend on how common the event is, but precision does. The same cut can now be too strict or too loose for what the mistakes cost.
Check yourself
You export a network with ONNX (torch) and add a static int8 copy. The export reports the copy's accuracy on sample rows it wasn't calibrated on. What should you still do before you deploy the int8 copy?
Show the answer
Answer: a
The copy was calibrated and checked on a small sample of training rows. Data that has shifted can push activations outside the calibrated ranges, so check the copy on data like the one it will score.
Call it from code
In the appStart the server, create an endpoint, and copy your token from Copy curl. Then call it. Rows go in as {"rows": [...]}, and the answer holds predictions, plus probabilities and classes for a classifier. If the version has a predictive SD or a saved conformal calibration, the answer also holds predSd, an interval as predLower and predUpper, or a prediction set as predSet. Without one, those fields are left out.
import requests
url = "http://127.0.0.1:8790/v1/models/churn:predict"
headers = {"Authorization": "Bearer YOUR_TOKEN"}
rows = {"rows": [{"age": 41, "plan": "plus", "visits": 3}]}
r = requests.post(url, json=rows, headers=headers, timeout=30)
r.raise_for_status()
print(r.json()["predictions"])library(httr2)
url <- "http://127.0.0.1:8790/v1/models/churn:predict"
rows <- list(rows = list(list(age = 41, plan = "plus", visits = 3)))
resp <- request(url) |>
req_auth_bearer_token("YOUR_TOKEN") |>
req_body_json(rows) |>
req_perform()
resp_body_json(resp)$predictionsYour own endpoint's name and features go where churn, age, plan and visits are. Try it shows the exact shape your model expects.
Recap
Recap- Use a batch unless a decision really can't wait.
- The local server is for this machine; exports are how a model leaves it.
- Follow an alias to move with promotions, or pin a version to stay put.
- An endpoint returns a score. The threshold is a separate decision, and it can change while the model doesn't.