Pagination and idempotency
Page through long lists with limit and offset, and retry writes safely with Idempotency-Key.
This page covers two things that matter when your code talks to the API for a long time: reading long lists in pages, and repeating a request after a failure without doing the work twice.
Pagination
Most list endpoints return the whole collection as a JSON array. Lists that can grow without limit are paged with two query parameters:
| Parameter | Meaning |
|---|---|
limit | The maximum number of items to return |
offset | The number of items to skip |
Items are returned newest first. Endpoints that return an object also report the total number of items next to items, limit and offset.
| Endpoint | Default limit | Maximum limit |
|---|---|---|
GET /projects/{project_id}/runs | 50 | 200 |
GET /admin/audit-logs and GET /workspaces/{workspace_id}/audit-logs | 100 | 500 |
GET /admin/users | 100 | 500 |
| Drift alerts and retraining decisions | 20 | 200 |
Other paged lists, such as prediction logs and comments, work the same way. The interactive reference shows the exact limits of each endpoint. On endpoints with a maximum, a limit above it is rejected with 422, except GET /admin/users, which caps it.
This request reads the second page of 50 runs, and only the failed ones:
curl -s "$BASE/projects/$PROJECT/runs?limit=50&offset=50&status=failed" \
-H "X-API-Key: $MLFLOW_API_KEY"{
"items": [],
"total": 120,
"limit": 50,
"offset": 50
}To read everything, increase offset by limit until offset is greater than or equal to total. If runs are created while you read, an item can move to a later page, so de-duplicate by id when you need an exact export.
Idempotency keys
A network can fail after the server has done the work but before you receive the answer. If you retry a request that creates something, you may end up with it twice: two training runs, or two batch jobs, and the compute that goes with them.
An idempotency key prevents this. Add an Idempotency-Key header with a value that is unique for each intended operation, for example a UUID. If you repeat the request with the same key, mlflow does not start new work. It returns the resource that the first request created.
KEY=$(uuidgen)
curl -s -X POST "$BASE/experiments/$EXP/runs" \
-H "X-API-Key: $MLFLOW_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $KEY" \
-d '{"plan": "compare", "data_source_id": "...", "target": "churned"}'Rules:
- The key is a string of 1 to 255 characters. A UUID is ideal. Other lengths are rejected with
400. - Create the key once per operation and send the same key on every retry of that operation. Do not generate a new key for each attempt.
- Keys are remembered for 24 hours after the request finishes. They are scoped to your user and to the route, so two users, or two experiments, can use the same value without clashing.
- Generate a fresh key for each new operation and reuse the same key on every retry of that operation. Keep the key stable in a scheduled job to make it safe to run again within 24 hours.
Which endpoints accept them
| Endpoint | What the request is compared on |
|---|---|
POST /experiments/{experiment_id}/runs | The whole request body |
POST /deployments/{deployment_ref}/batch | The deployment, the file name, the SHA-256 hash of the file contents and the option ignore_extra_columns |
The header is ignored on other endpoints. Other requests that create resources (uploading a dataset, registering a model, deploying) are not covered, so do not retry them blindly after a timeout. First read the list to see whether the first attempt worked.
Replays and conflicts
| Situation | What you get |
|---|---|
| First request with a key | The normal answer (202 for a run). The key is stored. |
| Same key, same request, after the first one finished | The run or batch job the first request created, in its current state, with the header Idempotent-Replayed: true. No new work starts. |
| Same key, different request | 422 "Idempotency-Key was already used with a different request". Use a new key for a new request. |
| Same key while the first request is still running | 409 with Retry-After: 2. Wait, then retry with the same key. |
| The first request crashed halfway | Its claim expires after about two minutes (120 seconds by default); then a retry goes through as a new request. |
| The resource of the first request was deleted | The retry creates a new one. |
| The key store is unavailable | 503 with Retry-After: 5. Retry; mlflow refuses rather than risk a duplicate. |
Because a replay returns the current state, a replayed run may already be running or succeeded. Always read the status field of the response instead of assuming queued.
Related
Updated 2026-11-22