> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.meshapi.ai/llms.txt.
> For full documentation content, see https://developers.meshapi.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.meshapi.ai/_mcp/server.

# Batch API

> Submit requests inline, create a batch, poll for completion, and download results.

The Batch API is for asynchronous, high-volume inference jobs where you do not need an answer immediately.

## Workflow

1. Prepare a request bundle
2. Create a batch with `POST /v1/batches`
3. Poll `GET /v1/batches/{batch_id}`
4. Download results from `GET /v1/files/{file_id}/content`

## 1 & 2. Create the batch

Pass your requests inline — no separate file upload required.

```bash
curl https://api.meshapi.ai/v1/batches \
  -H "Authorization: Bearer <YOUR_RSK_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "requests": [
      {
        "custom_id": "doc-001",
        "body": {
          "model": "openai/gpt-4o-mini",
          "messages": [{ "role": "user", "content": "Summarize this note." }]
        }
      }
    ],
    "completion_window": "24h"
  }'
```

```ts
const batch = await client.batches.create({
  requests: [
    {
      custom_id: "doc-001",
      body: {
        model: "openai/gpt-4o-mini",
        messages: [{ role: "user", content: "Summarize this note." }],
      },
    },
  ],
  completion_window: "24h",
});
```

```python
from meshapi import BatchRequestItem, CreateBatchParams, MeshAPI

client = MeshAPI(base_url="https://api.meshapi.ai", token="rsk_...")

batch = client.batches.create(
    CreateBatchParams(
        requests=[
            BatchRequestItem(
                custom_id="doc-001",
                body={
                    "model": "openai/gpt-4o-mini",
                    "messages": [{"role": "user", "content": "Summarize this note."}],
                },
            )
        ],
        completion_window="24h",
    )
)
```

```go
batch, err := client.Batches.Create(ctx, meshapi.CreateBatchParams{
    Requests: []meshapi.BatchRequestItem{
        {
            CustomID: "doc-001",
            Body: map[string]interface{}{
                "model": "openai/gpt-4o-mini",
                "messages": []map[string]string{
                    {"role": "user", "content": "Summarize this note."},
                },
            },
        },
    },
    CompletionWindow: "24h",
})
```

```java
var item = new com.meshapi.sdk.types.batch.BatchRequestItem();
item.customId = "doc-001";
item.body = java.util.Map.of(
    "model", "openai/gpt-4o-mini",
    "messages", java.util.List.of(java.util.Map.of("role", "user", "content", "Summarize this note."))
);

var batchRequest = new com.meshapi.sdk.types.batch.CreateBatchRequest();
batchRequest.requests = java.util.List.of(item);
batchRequest.completionWindow = "24h";

var batch = client.batches().create(batchRequest);
```

## 3. Poll for status

```bash
curl https://api.meshapi.ai/v1/batches/batch_xyz789 \
  -H "Authorization: Bearer <YOUR_RSK_KEY>"
```

Common statuses:

* `validating`
* `in_progress`
* `completed`
* `failed`
* `cancelled`
* `expired`

## 4. Download results

When `status` is `completed`, the response includes `output_file_id`. Download the results via the Files API:

```bash
curl https://api.meshapi.ai/v1/files/<OUTPUT_FILE_ID>/content \
  -H "Authorization: Bearer <YOUR_RSK_KEY>" \
  -o results.jsonl
```

## Notes

* All requests in a batch must use the same model.
* Batch jobs are best for throughput, not low-latency interactive use.
* Use `GET /v1/batches` to list recent batches and `POST /v1/batches/{batch_id}/cancel` to cancel one.