Docs
Open app
On this page

Train a model and get predictions in the same call. Bring labeled or unlabeled examples.

One API key covers everything: training, downloads and predictions from your models’ prediction URLs. In API Keys, select New Key under Training API and save the secret when it appears; it is shown only once. See account access if you need an account.

Endpoint

POST https://training.19th.com/v1/fit
Authorization: Bearer YOUR_API_KEY
Idempotency-Key: YOUR_UNIQUE_REQUEST_KEY
Content-Type: multipart/form-data; boundary=...

Use an account or project training API key. Fit needs training:write; status and downloads need training:read. Optional predictions and the returned model-version prediction URL also require inference:invoke. Keep the key in your backend. No project UUID is needed.

Choose your own unique Idempotency-Key for each new training request; reuse it when retrying that request. Curl sets the multipart content type and boundary for you.

Scopes and project access
ScopeAllows
training:writeSubmit fit or training and request cancellation
training:readRead fit status, capabilities, runs, results and downloads
data:writeCreate datasets and upload or finalize data in the staged workflow
data:readRead datasets and preparation state
models:readDiscover SDK runtimes

Project routes use the key’s API project UUID. training:projects enables account-wide placement where granted; a run’s run_project_id only groups runs and never grants access. Hosted inference has separate key requirements.

Request

Send two parts: request JSON first, then CSV file. The CSV holds training rows. Optional predict records are separate inputs to predict after training.

Use one flat table with a header row and the declared input columns. Keep known labels; use the optional labeling workflow only when the target is absent or empty. Training validates the columns, values and usable rows before fitting. Files can be up to 2 GiB; if a request returns 413, reduce the file before retrying.

This example labels customer training rows, trains a cancellation model and predicts one new customer. Omit spec.labeling when your CSV already has labels; omit predict when you only need the model. With labeling, the target column must be absent or empty. Save this as fit-request.json; the upload helper replaces FILE_SHA256 and the sample byte count with the real file values.

{
  "name": "Predict customer cancellation",
  "file": {
    "content_length": 12345,
    "sha256": "FILE_SHA256"
  },
  "spec": {
    "target_column": "churned",
    "input_columns": ["account_age_days", "monthly_spend"],
    "output_kind": "event_probability",
    "positive_label": "yes",
    "training_mode": "ultra",
    "labeling": {
      "description": "Predict whether this customer will cancel in the next 30 days",
      "classes": ["no", "yes"]
    }
  },
  "model_variant": "fast",
  "wait": true,
  "inline": false,
  "predict": [
    {
      "account_age_days": 365,
      "monthly_spend": 49.5
    }
  ]
}
namestringRequired

A 2–7 word title, at most 80 characters

file.content_lengthintegerRequired

Exact CSV byte count; calculated by the upload helper

file.sha256stringRequired

File fingerprint: 64 lowercase hex characters, without a prefix; calculated by the upload helper

spec.target_columnstring

Column to predict. Required except for label_set

spec.input_columnsstring[]Required

Columns available when predicting; exclude target, group and candidate columns

spec.output_kindstringRequired

The output you need, such as a label, probability or number

spec.positive_labelstring / number / boolean

Required only for event_probability; match the label’s exact type

spec.training_modestringRequired

instant, standard or ultra; choose explicitly, no default

spec.labelingobject

Use for classification when your training rows have no labels. Describe what you want to predict and the possible labels; we label a sample, then train your model. Not available with text or embedding columns

spec.text_columnsstring

hosted reads free-text columns with 19th’s language model. ignore (the default) leaves them out with a warning. See Text

spec.column_typesobject

Per-column overrides: vector reads an embedding column (required for base64 embeddings), text treats a column as free text, and categorical keeps a text-looking column as a category. For example {"photo_emb": "vector", "plan_notes": "categorical"}

spec.pairsstring[][]

Pairs of embedding input columns to compare, for example [["query", "title"]]

model_variantstring

fast (default), turbo or warpspeed

waitbooleanRequired

true: wait up to 85 seconds after upload acceptance. false: return without waiting

inlinebooleanRequired

false: JSON with a model download link. true: the same JSON plus model bytes when ready

predictobject[]

Send new inputs alongside your training data to get predictions from the trained model in the same result. Up to 1,000 records; requires a training key with inference:invoke. Omit when you only need the model

spec.training_mode controls training effort independently of model_variant, which selects the model file used for downloads and predictions.

Prediction records use exactly the declared input columns, with scalar or null values. Send text columns as raw text and embeddings as base64 strings. Ranking records also include their declared group and optional candidate fields.

Upload with curl

Requires curl, jq and uuidgen. Keep the key and request for retries. sha256 is the file fingerprint: 64 lowercase hex characters, without a sha256: prefix. Curl sets multipart headers automatically.

export TRAINING_ORIGIN="https://training.19th.com"
export API_KEY="YOUR_API_KEY"
export DATASET_FILE="customers.csv"
FIT_KEY="$(uuidgen)"
FILE_BYTES=$(wc -c < "$DATASET_FILE" | tr -d '[:space:]')
FILE_SHA256=$(shasum -a 256 "$DATASET_FILE" | cut -d ' ' -f 1)

jq --argjson bytes "$FILE_BYTES" --arg sha256 "$FILE_SHA256" \
  '.file = {content_length: $bytes, sha256: $sha256}' \
  fit-request.json > request.json

curl --fail-with-body -sS "$TRAINING_ORIGIN/v1/fit" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Idempotency-Key: $FIT_KEY" \
  -F 'request=<request.json;type=application/json' \
  -F "file=@$DATASET_FILE;type=text/csv" > fit.json
Train with unlabeled data

The optional spec.labeling object in the request labels the training CSV, not the separate predict records. Keep target_column and input_columns explicit.

spec.labeling.descriptionstringRequired

What to predict and what the classes mean; 1–4,000 characters

spec.labeling.classesscalar[]Required

2–256 distinct, nonblank, non-null values of one scalar type. Include the exact positive_label for probabilities

Inputs must exist. The target may be absent or entirely empty; any supplied value—including false, 0 or literal NA—refuses labeling. Use two classes for binary outputs, at least three for multiclass. Labeling supports binary_label, multiclass_label and event_probability. Omit it when you already have labels.

We label a sample, then train. wait: true covers labeling, training and delivery within the same 85-second limit; unfinished work returns 202 and continues in the background.

Train with text columns

Set spec.text_columns to hosted to use free-text columns, such as a support message. Send the text as it is in the CSV and in predict records; 19th reads it with its language model. Text columns can’t be combined with spec.labeling, so the CSV needs labels.

{
  "name": "Route support tickets",
  "file": {
    "content_length": 12345,
    "sha256": "FILE_SHA256"
  },
  "spec": {
    "target_column": "team",
    "input_columns": ["plan", "subject", "message"],
    "output_kind": "multiclass_label",
    "training_mode": "ultra",
    "text_columns": "hosted"
  },
  "wait": true,
  "inline": false,
  "predict": [
    {
      "plan": "pro",
      "subject": "Charged twice",
      "message": "I was charged twice for my November invoice. Can you refund one of the charges?"
    }
  ]
}

Columns where most values are different and average four or more words are read as text. Use column_types to mark another column as text, or to keep a text-looking column as categorical. The result’s warnings name any text columns that were left out.

Output kinds

Set spec.output_kind for the capability you need. Every spec includes input_columns and training_mode. Each capability’s inputs and outputs are described in Capabilities.

Capabilityspec.output_kindAlso set
Binary classificationbinary_label for a label, event_probability for a probabilitytarget_column with exactly two values. For event_probability, positive_label in the column’s type
Multiclass classificationmulticlass_labeltarget_column with three or more values
Ordinal classificationordered_classtarget_column and order: 2–256 values of one type, lowest to highest
Multilabel classificationlabel_settarget_columns, one two-value column per label; omit target_column
Regressionnumeric_valuetarget_column with numbers
Count regressioncount_valuetarget_column with whole numbers of 0 or more. Optional count_target: auto, raw, log1p or log1p_qmean
Rankingranking_scoreRelevance target_column of 0 or more, group_column and optional candidate_column
Forecastingnumeric_value or count_valueAs for regression or count regression

Exclude target, group and candidate columns from input_columns. For ranking, include the group and any candidate field in predict records.

Request examples

Binary classification, label

{
  "target_column": "churned",
  "input_columns": ["account_age_days", "monthly_spend"],
  "output_kind": "binary_label",
  "training_mode": "ultra"
}

Binary classification, probability

{
  "target_column": "churned",
  "input_columns": ["account_age_days", "monthly_spend"],
  "output_kind": "event_probability",
  "positive_label": "yes",
  "training_mode": "ultra"
}

Multiclass classification

{
  "target_column": "team",
  "input_columns": ["plan", "message_length"],
  "output_kind": "multiclass_label",
  "training_mode": "ultra"
}

Ordinal classification

{
  "target_column": "priority",
  "order": ["low", "medium", "high"],
  "input_columns": ["age_days", "amount"],
  "output_kind": "ordered_class",
  "training_mode": "ultra"
}

Multilabel classification

{
  "target_columns": ["urgent", "billing"],
  "input_columns": ["age_days", "amount"],
  "output_kind": "label_set",
  "training_mode": "ultra"
}

Regression

{
  "target_column": "sale_price",
  "input_columns": ["square_feet", "bedrooms"],
  "output_kind": "numeric_value",
  "training_mode": "ultra"
}

Count regression

{
  "target_column": "visits",
  "input_columns": ["age_days", "amount"],
  "output_kind": "count_value",
  "training_mode": "ultra"
}

Ranking

{
  "target_column": "relevance",
  "group_column": "query_id",
  "input_columns": ["age_days", "amount"],
  "output_kind": "ranking_score",
  "training_mode": "ultra"
}

Response

Completed work returns 200. This result includes the model and the optional predictions requested above. Uppercase values stand for returned IDs, file fingerprints and the full hosted prediction URL. IDs are UUIDs; use PREDICTION_URL for hosted predictions. Values are illustrative:

{
  "request_id": "fit-example",
  "run_id": "RUN_ID",
  "state": "ready",
  "status_url": "/v1/fit/RUN_ID?inline=false",
  "download_state": "ready",
  "model": {
    "model_id": "MODEL_ID",
    "model_version_id": "MODEL_VERSION_ID",
    "download": {
      "url": "https://download.example/model.tfpb",
      "expires_at": "2026-10-14T00:00:00Z",
      "format": "tfpb",
      "size_bytes": 28288,
      "sha256": "MODEL_SHA256"
    },
    "prediction": {
      "state": "ready",
      "url": "PREDICTION_URL"
    }
  },
  "predictions_state": "ready",
  "predictions": [
    {
      "input": {
        "account_age_days": 365,
        "monthly_spend": 49.5
      },
      "prediction": {
        "event_probability": 0.31,
        "label": "no",
        "probabilities": [0.69, 0.31]
      }
    }
  ]
}
FieldMeaning
statepreparing, training or packaging: work continues. cancelling: cancellation requested. ready, failed or cancelled: automatic work is finished
modelWhen a registered version is identified, keep model_id and model_version_id. Registered training is never reported as a failed fit
download_stateready: download. pending: keep reading. unavailable: inspect error
predictions_stateWhen requested: ready: use predictions. pending: keep reading. failed: inspect predictions_error; the model remains usable
model.predictionHosted prediction readiness and URL, separate from download readiness

A ready result can still have an unavailable download or failed optional predictions. Check these fields separately. Saved predictions preserve their input records and order.

With inline: false, the response is JSON with a download link. With inline: true, a ready fit and ready download return multipart: the same JSON in result, plus the model file in model. Pending and failed outcomes remain JSON. Check Content-Type before parsing; the multipart body itself is not a model file.

Downloads and SDKs

Fit returns your selected model as a single .tfpb file, without an SDK. Fast is the default. Once download_state is ready, use model.download.url:

DOWNLOAD_URL=$(jq -r '.model.download.url' fit.json)
curl --fail-with-body -sS "$DOWNLOAD_URL" -o model.tfpb
wc -c < model.tfpb
shasum -a 256 model.tfpb

Compare the byte count and SHA-256 with the response. Send the bearer only to the API, never to the download URL. Read fit again to refresh an expired link.

Run it locally. Load the .tfpb file with the 19th SDK for your language; Run models locally shows how. GET /v1/model-runtimes lists SDK packages and platform requirements. Select a returned runtime_id with GET /v1/model-runtimes?runtime_id=RUNTIME_ID to get its download and setup instructions. Install a compatible SDK once and reuse it across models.

Hosted-only models. Most models can be downloaded. When a run’s models can only be used through hosted predictions, GET /v1/training-runs/{run_id}/model-download-options returns downloadable: false with a hosted_only_reason, such as hosted_text_encoder, and download requests are refused. Check downloadable before offering a download, and use the hosted prediction URL instead.

Other model versions. To download Fast, Turbo or Warpspeed, use your fit run_id with GET /v1/training-runs/{run_id}/model-options, then request your selection through POST /v1/training-runs/{run_id}/model-downloads. Use the option IDs returned by the list. This uses the same training run; it does not retrain.

Download request example

GET /v1/model-download-options lists SDKs for custom bundles and returns catalog_version. Copy the exact runtime_id values and catalog version into the request. These are separate from the model option IDs above; uppercase values below are placeholders for returned values.

POST https://training.19th.com/v1/training-runs/{run_id}/model-downloads
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
{
  "model_ids": ["MODEL_OPTION_ID"],
  "format": "tfpb",
  "delivery": "archive",
  "runtime": {
    "mode": "selected",
    "targets": ["RUNTIME_ID"]
  },
  "catalog_version": "CATALOG_VERSION"
}
  • model_ids: one or more option IDs from the run’s model-options response.
  • delivery: archive (default) packages the selected models and SDKs in a ZIP. raw returns one model file and requires runtime.mode: "none".
  • runtime.mode: none (default) excludes SDKs; selected includes the SDKs in targets; all includes the newest qualified compatible SDK release for each concrete target of the selected models. Omit targets for none or all.
  • catalog_version: required for selected or all; copy it from the download-options response. Omit it for none. SDKs must support the selected models.

The response wraps the download in data. Keep data.download_id and read GET /v1/training-runs/{run_id}/model-downloads/{download_id} until data.state is ready or failed. When ready, data.download includes url, bytes and sha256; verify the downloaded file against them. If preparation fails, inspect data.failure_code and data.retryable. Repeat the same POST selection to retry a retryable failure. Status reads never restart preparation.

Retrieve the result

Fresh wait: false submissions, or requests still running after 85 seconds, return 202. Work continues; do not submit a new training job.

{
  "request_id": "fit-example",
  "run_id": "RUN_ID",
  "state": "training",
  "status_url": "/v1/fit/RUN_ID?inline=false"
}

Poll the returned status_url on the same origin. It already includes required inline. Optional wait_seconds accepts 0–85:

STATUS_URL=$(jq -r '.status_url' fit.json)
curl --fail-with-body -sS "$TRAINING_ORIGIN$STATUS_URL&wait_seconds=85" \
  -H "Authorization: Bearer $API_KEY" > fit.json

Status reads and terminal submission replays return 200, including saved failures. Check state and error. A read timeout leaves the run running.

To cancel, POST https://training.19th.com/v1/fit/{run_id}/cancel with your bearer and an idempotency key, then read status to confirm. Registered models are unaffected.

Staged uploads and training

GET /v1/training-capabilities lists the supported workflows:

WorkflowRequest and continuation
Upload and trainPOST /v1/projects/{project}/training-runs/upload: multipart spec JSON first, CSV file second; required Idempotency-Key. Spec contains file, explicit prediction, training_mode, run_name, and optional run_project_id. Read the returned run after 202.
Stage preparationCreate a dataset with prepared_training; request its version upload slot; transfer bytes using returned method and headers; finalize; read until preparation is ready; submit prep_id, run_name and a training_mode to POST /v1/training-runs/prepared.
Resume or cancelList with intake=prepared; read or cancel with view=prepared. Use returned run handles, cursors and poll guidance.

Project-free routes choose placement for eligible account keys and retain a project key’s pin. Upload slots use top-level version and upload; most resources use data. Fit uses the result above. Other resource errors use their declared error envelope.

Errors

Request errors return an HTTP error status and JSON with code, message, retryable and optional field issues. A saved training failure can arrive with 200 OK; check state and error.

StatusWhat to do
400 Bad RequestCorrect the fields or data described in message and issues
401 UnauthorizedCheck that your API key is present and valid
403 ForbiddenCheck your key’s permissions and project access
404 Not FoundCheck the resource ID and whether your key can access it
409 ConflictThis key belongs to a different request. Recover the original request, or use a new key for new work
413 Payload Too LargeReduce the CSV size
415 Unsupported Media TypeSend multipart form data with request JSON first and CSV file second; let curl set the multipart headers
429 Too Many RequestsHonor Retry-After before retrying with the same request, bytes and key
500 Internal Server Error, 503 Service UnavailableFollow retryable and Retry-After when supplied; retain the request ID and retry the existing request

For a saved TRAINING_FAILED result, read message for the cause before submitting new work. For DOWNLOAD_UNAVAILABLE, replay the original POST/key only when retryable to retry packaging; GET only reads status. Otherwise use hosted prediction if available, without retraining. MODEL_REVOKED means the model can no longer be downloaded or invoked.

Keep the request JSON, CSV bytes, Idempotency-Key and run_id. The same key recovers the same run for seven days; only wait and inline may change. After expiry, read the saved run instead of resubmitting. If the submission response is lost, replay the exact request with the same bytes and key. Retrying recovers existing work; it does not mean starting a new training job.