---
title: "Batches API: run a JSONL file within 24 hours"
description: "Start a batch from an uploaded file, follow it from validating to completed, read its output and error files, and cancel it while lines still wait."
canonical: https://pentestllm.ai/docs/batches
generated: 2026-11-27T06:25:48.677Z
source: https://pentestllm.ai/docs/batches
base_url: https://api.pentestllm.ai/v1
---

[Docs](https://pentestllm.ai/docs) / API reference

# Batch execution API

Updated 2026-11-22. Published by PentestLLM.

Hand the gateway an uploaded JSONL file and it works through the lines inside a 24-hour window, so a repeatable review over hundreds of inputs needs no client loop. The four routes live under `https://api.pentestllm.ai/v1/batches`; upload the input first on [Batch files](https://pentestllm.ai/docs/files).

## Routes

| Route | Statuses |
| --- | --- |
| `POST /v1/batches` | 200, 400, 401, 404 |
| `GET /v1/batches` | 200, 401 |
| `GET /v1/batches/{batch_id}` | 200, 401, 404 |
| `POST /v1/batches/{batch_id}/cancel` | 200, 401, 404, 409 |

All four go by the default security of the document, so the normal key your client already holds is enough to drive a batch. Whether a console session could stand in for it, the OpenAPI document does not say.

## Create a batch

`POST /v1/batches` takes:

| Field | Type | Notes |
| --- | --- | --- |
| `input_file_id` | string, required | A file uploaded with purpose batch. |
| `endpoint` | string, required | /v1/chat/completions, /v1/completions, /v1/embeddings, /v1/responses or /v1/moderations. Every line of the file must use it. |
| `completion_window` | string, required | Only 24h. |
| `metadata` | object | Up to 16 string values, handed back on the batch. |

It answers `200` with the batch. An unknown endpoint, a window other than 24h, or a line whose url differs from the endpoint is `400 invalid_request`; an input file your organization does not have is `404 not_found`.

## How lines run

Each line goes through the same route a direct call would, under the key that created the batch, so its model allowlist, budget and limits apply line by line, with each charge held against the balance as it runs. Each line that runs is billed at the catalog rate less a 50% batch discount, and receipts and the usage log show the discounted charge. An organization’s lines run a few at a time. A batch on /v1/moderations depends on a moderation model being listed; see [Embeddings, rerank and moderation](https://pentestllm.ai/docs/retrieval-and-moderation).

## The batch object

| Field | Meaning |
| --- | --- |
| `id` | batch_ and 24 hex characters. |
| `object` | Always batch. |
| `endpoint` | The route every line runs on. |
| `input_file_id` | The uploaded file. |
| `output_file_id` | Set at the end when any line answered 2xx, else null. |
| `error_file_id` | Set at the end when any line failed or expired, else null. |
| `completion_window` | Always 24h. |
| `status` | Where the batch is in its lifecycle, below. |
| `created_at` | Also expires_at, plus in_progress_at, finalizing_at, completed_at, failed_at, expired_at, cancelling_at and cancelled_at once reached. Unix seconds. |
| `request_counts` | total, completed and failed lines. |
| `errors` | An object or null. |
| `metadata` | What you sent, or null. |

`status` moves through validating, in_progress, finalizing and completed, or ends at failed, expired or, after a cancel, cancelling and then cancelled. The output file holds the lines that answered 2xx; the error file holds every other answer plus any line not reached before the window closed, marked batch_expired. That code appears inside the file, never as the HTTP status of a route. Read both files through the content route on Batch files.

## List and read

`GET /v1/batches` answers `object` list, `data`, `first_id`, `last_id` and `has_more`, newest first. Its prose takes `limit` (20 by default, 100 at most) and `after`, a batch id to continue from, though neither is a declared parameter. `GET /v1/batches/{batch_id}` returns one batch, or `404 not_found` when it is not your organization’s. A failed credential is `401 invalid_api_key` on every route.

## Cancel

`POST /v1/batches/{batch_id}/cancel` takes no body. Lines not yet started are dropped, answered ones stay in the output file, and the batch reads cancelling until its running lines finish, then cancelled. A batch that already finished answers `409 batch_not_cancellable`.

## Example

```bash
curl "https://api.pentestllm.ai/v1/batches?limit=20" \
  -H "Authorization: Bearer sk-ptl-live-…"
```

## Questions

### Can one batch call more than one route?

No. A batch names a single endpoint, and a file with any line pointing somewhere else is rejected when you create the batch.

### Does cancelling throw away finished lines?

No. Answers already produced stay in the output file, and lines that are running finish before the batch settles as cancelled.

### What becomes of lines the window did not reach?

They land in the error file with the code batch_expired, so you can collect them and submit a new batch.

## Read next

- [MCP servers](https://pentestllm.ai/docs/mcp-servers)
- [Log export](https://pentestllm.ai/docs/exports)
- [Invoices](https://pentestllm.ai/docs/invoices)
- [Billing details](https://pentestllm.ai/docs/billing-details)
- [Statement signing key](https://pentestllm.ai/docs/statements-public-key)
- [Keys and scopes](https://pentestllm.ai/docs/keys)
- [Usage and signed receipts](https://pentestllm.ai/docs/usage-and-receipts)
- [Spend limits and balance](https://pentestllm.ai/docs/spend-limits)
- [Redaction and guardrails](https://pentestllm.ai/docs/redaction-and-guardrails)
- [Sessions](https://pentestllm.ai/docs/sessions)
- [Embeddings, rerank and moderation](https://pentestllm.ai/docs/retrieval-and-moderation)
- [Batch files](https://pentestllm.ai/docs/files)
- [Status and proof feeds](https://pentestllm.ai/docs/status-and-proof)
- [Count tokens](https://pentestllm.ai/docs/count-tokens)
- [Usage by app](https://pentestllm.ai/docs/stats-apps)
- [App sign-in keys](https://pentestllm.ai/docs/auth-keys)
- [Webhook deliveries](https://pentestllm.ai/docs/webhooks-deliveries)
- [Docs: connect in two minutes](https://pentestllm.ai/docs)
- [Endpoints](https://pentestllm.ai/features/endpoints)
