# Inference API

Send records or a CSV and get predictions. Call your model's prediction URL, or download the model and run it in your app with our SDK.

Use the same API key you train with: a key created under **Training API** in [API Keys](https://app.19th.com/api-keys) also calls your models' prediction URLs. Create a key under **Inference API** only when you want one that can just predict, for example a key limited to specific models for a production app. Save the secret when it appears; it is shown only once. See [account access](/docs#get-access) if you need an account.

## Endpoint

<span id="authentication"></span>
<span id="make-a-prediction"></span>


```http label=Endpoint
POST https://inference.get19th.com/v1/models/{model_id}/versions/{model_version_id}/predictions
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```

Set `PREDICTION_URL` to the exact `model.prediction.url` returned by fit. For an existing hosted endpoint, use `https://inference.get19th.com/v1/endpoints/YOUR_ENDPOINT_UUID/predictions`.

Keep the key in your backend.

Model-version routes accept your training key or an inference key with access to that model. Endpoint routes use inference keys (`19th_inf_...`). MCP sign-in is separate and doesn't need a key.

Check `model.prediction.state`: `ready` → use its URL; `loading` → retry shortly; `unavailable` → hosted prediction is unavailable. Download readiness is separate.

## Request

Save this as `prediction-request.json`:


```json label=Request
{
  "input": [
    {
      "account_age_days": 365,
      "monthly_spend": 49.5
    }
  ],
  "metadata": {
    "source": "quickstart"
  }
}
```

<details class="schema-detail">
<summary>Send with curl</summary>

```sh label=Shell
export API_KEY="YOUR_API_KEY"
export PREDICTION_URL="PREDICTION_URL_RETURNED_BY_19TH"

curl --fail-with-body -sS "$PREDICTION_URL" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Request-Id: cancellation-example" \
  --data-binary @prediction-request.json
```

</details>

| Field | Required? | Meaning |
| --- | --- | --- |
| `input` | Required | One input object or an array; use the model's raw names and types, without target labels |
| `metadata` | Optional | Echoed string values, not predictor inputs: up to 16 keys, 1–64 UTF-8 bytes each; values up to 512 bytes |
| `model` | Optional | Must match the route's model identifier when supplied |

Unknown top-level fields are rejected. Send raw inputs, not engineered features.

<span id="text-and-embeddings"></span>

**Text and embeddings.** For a model trained with [text columns](/docs/capabilities#text), send each text column's raw text; 19th reads it with the same language model used in training. Each text cell holds up to 64 KiB. Alternatively, send the column's vector as `<column>__emb`, for example `message__emb`, as a JSON array or base64 float32 string. Send the text or the vector in a record, not both. Embedding columns take a JSON array of numbers or a base64 string.

Predictions from text take longer than predictions from numbers and categories alone, because the text is read first. Send large volumes of text through [batch inference](#batch-inference).




## Response

A response for an event-probability model might look like this. `MODEL_ID` and `MODEL_VERSION_ID` stand for UUIDs returned by the API:


```json label=Response
{
  "id": "pred_example",
  "object": "prediction.list",
  "created": 1790000000,
  "model": "MODEL_ID",
  "model_version": "MODEL_VERSION_ID",
  "request_id": "cancellation-example",
  "output": [
    {
      "event_probability": 0.31,
      "label": "no",
      "probabilities": [0.69, 0.31]
    }
  ],
  "classes": ["no", "yes"],
  "usage": {
    "records": 1,
    "source_rows": 0
  },
  "metadata": {
    "source": "quickstart"
  }
}
```

<span id="forecast-ranges"></span>

Each `output` entry depends on the model's capability; [Capabilities](/docs/capabilities) describes each one. Keep class order and typed labels beside probabilities. `request_id` also appears in `X-Request-Id`; retain it for support. `usage` counts records and source rows.


<details class="schema-detail" id="additional-task-outputs">
<summary>Batch CSV and ranking outputs</summary>

CSV puts the main output in `prediction` and the full output in `prediction_details`; a multilabel main output is a JSON boolean vector in one cell. Do not reorder axes, round counts or recalculate ranks.

Ranking requests include declared group and optional candidate metadata without target labels. Each group is ranked against that group’s candidates supplied in the JSON request. For CSV, keep each group's rows contiguous and small enough for one inference chunk; a group cannot reappear after another group. If a group or tracking limit is refused, reduce candidates or split the file while preserving whole groups.

</details>

## Batch inference

<span id="predict-from-a-csv"></span>

```http label=Endpoint
POST https://inference.get19th.com/v1/models/{model_id}/versions/{model_version_id}/batch
Authorization: Bearer YOUR_API_KEY
Idempotency-Key: YOUR_UNIQUE_REQUEST_KEY
Content-Type: multipart/form-data; boundary=...
```


Use a registered model version. Send `request` JSON first, then CSV `file` with the model's input columns; maximum 64 MiB (67,108,864 bytes).

| Request field | Required? | Meaning |
| --- | --- | --- |
| `wait` | Required | `true`: wait up to 45 seconds from request start, including upload. `false`: return without waiting |
| `inline` | Required | `false`: JSON and a CSV download link. `true`: JSON and CSV bytes in one multipart response when ready |
| `metadata` | Optional | The same echoed string map as JSON predictions |

Save the request as `batch-request.json`:

```json label=Request
{
  "wait": true,
  "inline": false
}
```

<details class="schema-detail">
<summary>Upload the CSV with curl</summary>

```sh label=Shell
export API_KEY="YOUR_API_KEY"
export INFERENCE_ORIGIN="https://inference.get19th.com"
export MODEL_ID="MODEL_UUID_RETURNED_BY_19TH"
export MODEL_VERSION_ID="MODEL_VERSION_UUID_RETURNED_BY_19TH"
BATCH_KEY="$(uuidgen)"

curl --fail-with-body -sS \
  "$INFERENCE_ORIGIN/v1/models/$MODEL_ID/versions/$MODEL_VERSION_ID/batch" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Idempotency-Key: $BATCH_KEY" \
  -F 'request=<batch-request.json;type=application/json' \
  -F 'file=@prediction-inputs.csv;type=text/csv' > batch.json
```

</details>

A pending response uses HTTP 202. `BATCH_ID` stands for the returned batch UUID:

```json label=Response
{
  "request_id": "batch-example",
  "batch_id": "BATCH_ID",
  "state": "processing",
  "status_url": "/v1/models/MODEL_ID/versions/MODEL_VERSION_ID/batch/BATCH_ID"
}
```

Poll the returned path with required `inline` and optional `wait_seconds` (0–45):

```sh label=Shell
BATCH_STATUS_URL=$(jq -r '.status_url' batch.json)
curl --fail-with-body -sS \
  "$INFERENCE_ORIGIN$BATCH_STATUS_URL?inline=false&wait_seconds=45" \
  -H "Authorization: Bearer $API_KEY" > batch.json
```

Reads return 200 with `processing`, `ready` or `failed`; a timeout leaves work running. On `ready`, follow `download.url`, verify `size_bytes` and `sha256`, and read status to refresh an expired link. Never send the API bearer to the download URL.

A completed result can look like this. `PREDICTIONS_SHA256` stands for the file’s SHA-256 fingerprint; other values are illustrative:

```json label=Response
{
  "request_id": "batch-example",
  "batch_id": "BATCH_ID",
  "state": "ready",
  "status_url": "/v1/models/MODEL_ID/versions/MODEL_VERSION_ID/batch/BATCH_ID",
  "rows": 10,
  "download": {
    "url": "https://download.example/predictions.csv",
    "expires_at": "2026-10-14T00:00:00Z",
    "format": "csv",
    "size_bytes": 2048,
    "sha256": "PREDICTIONS_SHA256"
  }
}
```

With `inline: true`, ready results are multipart: the same JSON in `result`, plus the CSV in `predictions`. Pending and failed outcomes stay JSON. Check Content-Type. Use `inline: false` for large files; the entire request and inline delivery have a 55-second budget.

The CSV keeps input columns and row order, adding `prediction` (the main output) and `prediction_details` (the full output as JSON text). Existing names get collision suffixes. Failed batches publish no partial file.

**Retention.** A batch's input and result files are deleted after the retention window: 24 hours after the batch finishes by default. Download results promptly. After that, reads return `410` with `batch_expired`; submit the CSV again with a new `Idempotency-Key`.

**Concurrency.** Each API key can have 2 batch requests in flight, separate from JSON predictions. A third returns `429`; a busy service returns `503`. Both include `Retry-After`: wait that long, then retry the same request or read the known `status_url`.


## Errors

Request errors return an HTTP error status and a JSON body with a request ID and actionable details:

```json label=Response
{
  "object": "error",
  "request_id": "cancellation-example",
  "error": {
    "type": "invalid_request_error",
    "code": "invalid_request",
    "message": "input is required",
    "param": "input",
    "retryable": false,
    "details": {}
  }
}
```

| Status | What to do |
| --- | --- |
| `400 Bad Request` | Correct the fields described in the error |
| `401 Unauthorized` | Check that your API key is present and valid |
| `403 Forbidden` | Check your key’s permissions, restrictions and project access |
| `404 Not Found` | Check the model/version or endpoint ID and your access |
| `409 Conflict` | The batch key belongs to different work; recover the original request |
| `410 Gone` | `batch_expired`: the batch's files were deleted after the retention window. Submit the CSV again with a new key |
| `413 Payload Too Large` | Reduce request size; split oversized CSVs |
| `429 Too Many Requests`, `503 Service Unavailable` | Honor Retry-After and retryable; retry batch submission with the original key and exact bytes |
| `502 Bad Gateway`, `504 Gateway Timeout` | Retain the request ID and use bounded retries for temporary failures |

<span id="text-errors"></span>

Models with text columns can also return these codes in `error.code`:

| Code | Status | What to do |
| --- | --- | --- |
| <code class="error-code">TEXT_AND_EMBEDDING_BOTH</code> | `400` | A record sent both a text column and its `<column>__emb` vector. Send one |
| <code class="error-code">TEXT_CELL_TOO_LARGE</code> | `400` | A text cell is over 64 KiB. Shorten the text |
| <code class="error-code">TEXT_TOKENS_OVER_LIMIT</code> | `400` | The request holds too much text to read at once. Send fewer records, or use batch inference |
| <code class="error-code">TEXT_ENCODER_UNAVAILABLE</code> | `503` | Reading text is briefly unavailable or busy. Retry after `details.retry_after_seconds`; `details.reason` says why |

Batch keys bind model/version, CSV bytes and metadata for seven days; `wait` and `inline` may change. Results stay readable through the shorter retention window above. Terminal status reads do not run prediction again. A saved batch failure can arrive with **200 OK**, so inspect `state` and `error`.

JSON defaults: 4 MiB, 1,000 records or 10,000 source rows, 30-second prediction timeout. Key/deployment limits also apply. Retry temporary failures as instructed; fix malformed inputs first.
