> ## Documentation Index
> Fetch the complete documentation index at: https://docs.metaphi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Batches

> Twin up to 10,000 traces with one request. API version 2026-11-25.

A `batch` holds up to 10,000 requests. Each request twins one input [file](https://docs.metaphi.ai/kennet/api/2026-11-25/files.md) and ends with one `result`: an output file or an [error](https://docs.metaphi.ai/kennet/api/2026-11-25/errors.md). A single trace is a batch of one request.

Send `Metaphi-Version: 2026-11-25`. See [API versions](https://docs.metaphi.ai/kennet/api/2026-11-25/versions.md).

## The batch object

```json theme={"dark"}
{
  "id": "batch_5e0b...",
  "object": "batch",
  "status": "in_progress",
  "request_counts": {
    "total": 2000, "queued": 1460, "running": 120, "requires_action": 0,
    "succeeded": 412, "failed": 8, "canceled": 0, "expired": 0
  },
  "created_at": 1764028800,
  "ended_at": null,
  "canceled_at": null,
  "expired_at": null,
  "expires_at": 1764633600,
  "error": null,
  "estimated_cost_usd": 412.0,
  "balance_needed_usd": null,
  "livemode": true,
  "results_url": null
}
```

| Field | Type | Description |
| - | - | - |
| `id` | string | Unique identifier, prefixed `batch_` |
| `object` | string | `batch` |
| `status` | enum | See [batch statuses](#batch-statuses) |
| `request_counts` | object | `total`, and the number of requests in each [request status](#request-statuses) |
| `created_at` | integer | Creation time, in Unix seconds |
| `ended_at` | integer or null | Time it ended |
| `canceled_at` | integer or null | Time a cancel was requested |
| `expired_at` | integer or null | Time it expired |
| `expires_at` | integer or null | Time it expires if still open. `null` while `requires_action` and once ended |
| `error` | object or null | Set while `requires_action`: a `billing_error` with `action_url` |
| `estimated_cost_usd` | number or null | Estimated price of every request. `null` in test mode or when unavailable |
| `balance_needed_usd` | number or null | Credit to add so every request not yet started can run. `null` when covered, and once ended |
| `livemode` | boolean | `false` in test mode |
| `results_url` | string or null | Path of the [results](#download-a-batchs-results). Set once ended |

## Batch statuses

| Status | Meaning |
| - | - |
| `in_progress` | At least one request is open |
| `requires_action` | Prepaid credit is exhausted. Queued requests wait; running requests continue. Returns to `in_progress` when credit is added |
| `canceling` | A cancel was requested; running requests are finishing |
| `ended` | Every request has ended. Final. `canceled_at` or `expired_at` says why, if not all ran |

A batch not ended 7 days after creation, excluding time in `requires_action`, expires: its open requests become `expired`.

## The request object

A request has no id of its own. It is named by its `batch_id` and your `custom_id`.

```json theme={"dark"}
{
  "object": "batch_request",
  "batch_id": "batch_5e0b...",
  "custom_id": "trace-0001",
  "status": "succeeded",
  "input_file_id": "file_3a9e...",
  "end_user": "cust_8812",
  "result": {
    "output_file": {
      "id": "file_9c2d...", "object": "file", "purpose": "output",
      "filename": "trace-0001.jsonl", "bytes": 48213, "sha256": "4b1f...",
      "created_at": 1764029100, "expires_at": 1766621100, "livemode": true
    },
    "error": null
  },
  "created_at": 1764028800,
  "started_at": 1764028860,
  "ended_at": 1764029100,
  "livemode": true
}
```

| Field | Type | Description |
| - | - | - |
| `object` | string | `batch_request` |
| `batch_id` | string | The batch |
| `custom_id` | string | Your identifier for the request, unique in the batch |
| `status` | enum | See [request statuses](#request-statuses) |
| `input_file_id` | string or null | The input file. `null` for an anonymization created in `2026-10-11` |
| `end_user` | string or null | As sent |
| `result.output_file` | object or null | The output [file](https://docs.metaphi.ai/kennet/api/2026-11-25/files.md), once `succeeded`, without `downloaded_at`. Retrieve the file for when it was downloaded |
| `result.error` | object or null | Set when `failed`, `expired` or `requires_action`. See [errors](https://docs.metaphi.ai/kennet/api/2026-11-25/errors.md) |
| `created_at` | integer | Its batch's creation time |
| `started_at` | integer or null | Time it started running |
| `ended_at` | integer or null | Time it ended |
| `livemode` | boolean | `false` in test mode |

## Request statuses

| Status | Meaning |
| - | - |
| `queued` | Waiting to start |
| `running` | Being twinned. A failure on our side is retried while running |
| `requires_action` | Waiting for credit. Returns to the status it left when credit is added |
| `succeeded` | Final. `result.output_file` is set. Charged. See [charges](#charges) |
| `failed` | Final. `result.error` says why |
| `canceled` | Final. Canceled before it started |
| `expired` | Final. Not ended before its batch expired |

A request starts `queued` and ends in one of the four final statuses. It can end without running: `canceled` by a cancel, `failed` if its input is refused or credit ran out before it could run, or `expired` with its batch. While `queued` or `running` it can move to `requires_action` and back. It never leaves a final status.

## Charges

A succeeded request is charged your organization's price. Failed, canceled and expired requests are never charged. Test mode is free.

To reconcile, list `GET /v1/kennet/balance_transactions`. Each transaction of type `usage` carries the `batch_id` and `custom_id` of the request it charged.

## Create a batch

`POST /v1/kennet/batches`

Send JSON with an [`Idempotency-Key`](https://docs.metaphi.ai/kennet/api/idempotency) header. Maximum body size: 4 MiB.

| Parameter | Type | Required | Description |
| - | - | - | - |
| `requests` | array | yes | 1 to 10,000 requests |
| `requests[].custom_id` | string | yes | Unique in the batch. 1 to 64 letters, digits, `_` and `-` |
| `requests[].input_file_id` | string | yes | An input file no batch has taken, named once |
| `requests[].end_user` | string | no | Your identifier for the customer the trace belongs to. Never a name or email |

```sh theme={"dark"}
curl https://api.metaphi.ai/v1/kennet/batches \
  -H "Authorization: Bearer $API_KEY" \
  -H "Metaphi-Version: 2026-11-25" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"requests": [{"custom_id": "trace-0001", "input_file_id": "file_3a9e..."}]}'
```

**Returns** `202` with a `batch` in `in_progress`, or `requires_action` if prepaid credit is exhausted. If any request is invalid, nothing is created: `400 parameter_invalid` names it, such as `requests.3.input_file_id`.

## Retrieve a batch

`GET /v1/kennet/batches/{batch_id}`

**Returns** a `batch`. Poll no more than once every 30 seconds, or use [events](https://docs.metaphi.ai/kennet/api/2026-11-25/events.md).

## List batches

`GET /v1/kennet/batches`

Newest first. `limit` 1 to 100 (default 10); `starting_after` a batch id.

## List a batch's requests

`GET /v1/kennet/batches/{batch_id}/requests`

In the order sent. `limit` 1 to 100 (default 100); `starting_after` a `custom_id`; `status` one request status.

## Retrieve a request

`GET /v1/kennet/batches/{batch_id}/requests/{custom_id}`

**Returns** a `batch_request`.

## Download a batch's results

`GET /v1/kennet/batches/{batch_id}/results`

One `batch_request` per line, as JSON Lines, in the order sent. Available once the batch has ended, else `409 resource_not_ready`. Results never change after the batch ends, except that an output's `filename` becomes `null` once the file is forgotten.

## Cancel a batch

`POST /v1/kennet/batches/{batch_id}/cancel`

Requests not yet started become `canceled`; running requests finish. **Returns** the `batch` in `canceling`. It becomes `ended` when its running requests end. `409 resource_state` if it has ended.

For a batch of one made by `POST /v1/kennet/twins` in `2026-10-11`, a request not yet started becomes `canceled` and the batch `ended`. A running request is not canceled: the batch is returned `in_progress` and ends when the request does.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.