Turn a fitted workflow into a callable service file
model development
deployment
vetiver
Learn how vetiver records a fitted text model, writes an API file, and keeps evaluation details attached before deployment.
A data team has a model that scores well enough for review. The next request is practical: can another system send it a paragraph and get back a label?
That request is about deployment. Deployment does not make a model smarter. It packages the fitted object, the expected input shape, and the code needed to call it later.
The safest deployment record also carries the evaluation that justified the model. Without that record, an API can make a weak answer look official.
TipWhat you will learn
This lesson shows how to:
wrap a fitted tidymodels workflow with vetiver;
pin the model to a local board;
inspect the prototype input saved with the model;
write the Plumber API file without starting a server; and
name the evaluation details that must travel with a deployed model.
Fit the model to be packaged
A deployment needs the same fitted object that evaluation approved. Here the object is the era classifier from a speech-held-out split with seed 4301 and fit seed 4302.
After a model design passes evaluation, a production team often refits it on all available labeled data. This lesson packages the held-out fit instead. That choice keeps the stored object tied to the exact live score shown below, which makes the provenance easier to inspect. A full-data refit would be a new object whose score came from earlier fits with the same design.
Evaluation details kept beside the deployable model
Record item
Value
data source
inaugural paragraphs
selected candidate
ridge logistic regression
selected penalty
0.01
selection resampling
five folds grouped by speech inside training
split scheme
speech_id group split
training paragraphs
1042
test paragraphs
335
live test accuracy
0.8209
live train-majority baseline
0.4179
speech-split mean accuracy
0.8457
speech-split mean train-majority baseline
0.6282
speech-split mean length baseline
0.6827
evaluation date
2026-08-29
Deployment freezes a model at one point in its life. The record above says which data split and score go with the object, and it records the baseline that makes the score interpretable. The repeated speech-split study matters because one live split can have an unusual class mix.
Pin the fitted workflow
vetiver_model() wraps the fitted workflow with metadata. A prototype is the empty input table the model expects. The local pins board is a storage place for versioned objects; this lesson writes to a project-local scratch board and removes it after reading the generated files.
The version lets a later system ask for this exact object. The prototype says the API expects a table with a paragraph column. The pinned board is the place the API reads from when it starts.
Write the API file without starting it
vetiver_write_plumber() writes an R file for a Plumber API. This lesson only writes and reads that file. It does not start a server and it makes no network request.
# Generated by the vetiver package; edit with carelibrary(pins)library(plumber)library(rapidoc)library(vetiver)# Packages needed to generate model predictionsif (FALSE) {library(glmnet)library(parsnip)library(recipes)library(stopwords)library(textrecipes)library(workflows)}b <-board_folder(path ="<local board path>")v <-vetiver_pin_read(b, "inaugural-era-workflow", version ="<pinned version>")#* @plumberfunction(pr) { pr |>vetiver_api(v)}
The file shown above was generated by vetiver. The local board path and version string are masked in the display so the rendered lesson stays stable, but the assertions read the generated file before masking it.
A deployment record must carry the selected candidate and settings, the data source, split scheme, score, baseline, and date. For this model, the live record is: ridge logistic regression with penalty 0.01, inaugural paragraphs, speech-held-out split, accuracy 0.8209, same-split training-majority baseline 0.4179, evaluation date 2026-08-29, and fixed seeds 4301 and 4302.
The party model with this recipe and penalty did not pass evaluation. It should not be deployed by wrapping it in an API. Packaging makes access easier; it does not repair a failed measurement.
What to remember
Deployment packages a fitted object so another system can call it.
A vetiver prototype records the input columns the model expects.
A pins board stores model versions.
Do not deploy a model that did not pass evaluation.
Keep the candidate, settings, data, split, score, baseline, and date with the deployed object.
An API turns a model into an answer people can request. It should also make the limits hard to lose.