---
description: "How the OpenAI Batch API works: JSONL format, limits, lifecycle, and code, plus how to run batch jobs on OpenAI, Claude, Bedrock, and Gemini through Bifrost."
title: "OpenAI Batch API: A Practical Guide to Batch Inference Across Providers"
image: https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w1200/2026/11/openai-batch-api-a-practical-guide-to-batch-inference-across-bifrost-1920x1080.png
---

Try Bifrost Enterprise free for 14 days. [Request access](https://www.getmaxim.ai/#enterprise-trial)

**TL;DR**

- The OpenAI Batch API processes large groups of requests asynchronously: you upload a JSONL file, create a batch, and download results within a 24-hour window.
- OpenAI documents 50% lower cost than synchronous calls, a separate and larger rate-limit pool, and limits of 50,000 requests and 200 MB per batch file.
- Batch inference fits evaluations, classification, enrichment, embeddings, and any job where nobody is waiting on the answer.
- Anthropic, Amazon Bedrock, and Google Gemini each offer batch APIs, but their input formats, limits, and storage requirements differ.
- Bifrost exposes the OpenAI Files and Batch APIs with cross-provider routing, so one OpenAI SDK workflow can submit batch jobs to OpenAI, Anthropic, Bedrock, or Gemini.

The OpenAI Batch API is the simplest way to run large volumes of model calls that do not need an immediate response, and most teams eventually need the same pattern on more than one provider. [Bifrost](https://www.getmaxim.ai), the [open-source AI gateway](https://github.com/maximhq/bifrost) built by Maxim AI, supports the OpenAI Files and Batch APIs and routes them to OpenAI, Anthropic, Bedrock, or Gemini from one SDK. This guide explains how the OpenAI Batch API works, its limits and lifecycle, and how to run batch inference across providers.

## What Is the OpenAI Batch API?

The OpenAI Batch API is an asynchronous endpoint for sending a large set of independent requests in one job. Instead of calling the API thousands of times and handling rate limits yourself, you write every request into a JSONL file, upload it, create a batch, and collect a results file when the job finishes.

OpenAI's [Batch API guide](https://developers.openai.com/api/docs/guides/batch) lists three advantages over synchronous calls:

- **Lower cost.** Batch requests are billed at 50% of the synchronous price.
- **Higher rate limits.** Batch traffic draws on a separate pool with substantially more headroom.
- **Predictable turnaround.** Each batch completes within 24 hours, often sooner.

Batches support endpoints including `/v1/responses`, `/v1/chat/completions`, and `/v1/embeddings`. The comparison of the [Responses API, Chat Completions, and Anthropic Messages](https://www.getmaxim.ai/articles/openai-responses-api-vs-chat-completions-vs-anthropic-messages/) covers which request format to choose for each line.

## When to Use Batch Inference

Batch inference fits any workload where results can wait minutes or hours and requests do not depend on each other. If a user is waiting on the screen, or one request needs the output of another, synchronous calls are the right tool. Otherwise, a batch job usually costs less and keeps bulk traffic away from production rate limits.

Common batch workloads:

- **Evaluations.** Run a test set of hundreds or thousands of prompts against a model or prompt version.
- **Classification and tagging.** Label support tickets, documents, or product listings in bulk.
- **Data enrichment.** Summarize, extract fields from, or translate large datasets.
- **Embeddings.** Generate embeddings for a content library or search index.
- **Backfills.** Reprocess historical records after a prompt or model change.

Figure 1 compares the two modes.

![An app sends one request and gets a response in seconds, while a JSONL file of requests runs as a batch job with results within 24 hours](https://articles-images-cdn.t3.tigrisfiles.io/diagrams/openai-batch-api/batch-vs-sync.png)

An app sends one request and gets a response in seconds, while a JSONL file of requests runs as a batch job with results within 24 hours

*Figure 1: Synchronous calls answer in seconds; batch jobs trade latency for lower cost and a separate, larger rate-limit pool.*

For the synchronous side of cost control, the guide to [monitoring LLM API costs in production](https://www.getmaxim.ai/articles/how-to-monitor-llm-api-costs-in-production/) covers tracking spend per request.

## OpenAI Batch API Limits

OpenAI Batch API limits apply per batch and per organization, and they are separate from the per-model limits on synchronous calls. Knowing them up front decides how a large job should be split into files and how many batches to create.

| Limit | Value |
| --- | --- |
| **Requests per batch** | Up to 50,000 |
| **Input file size** | Up to 200 MB |
| **Embedding inputs** | Up to 50,000 across all requests in an embeddings batch |
| **Batch creation rate** | Up to 2,000 batches per hour |
| **Completion window** | `24h` only |
| **Enqueued tokens** | Per-model cap on tokens waiting across all active batches |

What happens at the edges:

- **Expired batches.** If a batch does not finish within 24 hours, remaining requests are cancelled and completed results are still returned.
- **Cancellation.** A cancelled batch can take up to 10 minutes to stop.
- **Model support.** Most models support the Batch API, but not all; check the model reference before building a job.

The [OpenAI provider guide](https://www.getmaxim.ai/bifrost/guides/providers/openai) covers connecting OpenAI to Bifrost, and the [OpenAI API alternatives roundup](https://www.getmaxim.ai/articles/13-best-openai-api-alternatives/) covers other providers.

## How the OpenAI Batch API Works

The OpenAI Batch API follows a five-step lifecycle: prepare a JSONL file, upload it with `purpose="batch"`, create the batch with a `24h` completion window, poll its status, and download the output and error files. Each line carries a `custom_id` so results can be matched to inputs, because output order is not guaranteed.

![Five steps: prepare a JSONL file with custom IDs, upload it with purpose batch, create the batch with a 24-hour window, poll status, then download output and error files](https://articles-images-cdn.t3.tigrisfiles.io/diagrams/openai-batch-api/batch-lifecycle.png)

Five steps: prepare a JSONL file with custom IDs, upload it with purpose batch, create the batch with a 24-hour window, poll status, then download output and error files

*Figure 2: Every batch follows the same five steps; custom IDs tie each result line back to its input because output order is not guaranteed.*

### Step 1: Prepare the JSONL file

Each line is one request with a `custom_id`, the HTTP method, the endpoint, and the request body:

```json
{"custom_id": "ticket-001", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Classify this ticket: login fails after reset"}], "max_tokens": 50}}
{"custom_id": "ticket-002", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "gpt-4o-mini", "messages": [{"role": "user", "content": "Classify this ticket: invoice shows wrong currency"}], "max_tokens": 50}}
```

### Step 2: Upload the file

```python
from openai import OpenAI

client = OpenAI()

batch_file = client.files.create(
    file=open("batch_input.jsonl", "rb"),
    purpose="batch",
)
```

### Step 3: Create the batch

```python
batch = client.batches.create(
    input_file_id=batch_file.id,
    endpoint="/v1/chat/completions",
    completion_window="24h",
)
```

### Step 4: Poll the status

A batch moves through `validating`, `in_progress`, and `finalizing` before reaching `completed`, `failed`, `expired`, or `cancelled`:

```python
batch = client.batches.retrieve(batch.id)
print(batch.status, batch.request_counts)
```

### Step 5: Download the results

```python
if batch.status == "completed":
    output = client.files.content(batch.output_file_id)
    with open("batch_output.jsonl", "wb") as f:
        f.write(output.read())
```

Failed lines go to a separate error file referenced by `error_file_id`. The [OpenAI API pricing guide](https://www.getmaxim.ai/articles/openai-api-pricing/) covers how batch usage appears on bills.

## Batch APIs on Other Providers

Anthropic, Amazon Bedrock, and Google Gemini all offer batch processing, but each takes a different input shape. Teams that run evaluations or bulk jobs on more than one provider end up maintaining several batch clients, each with its own file handling, limits, and status codes.

| Provider | Input format | Storage | Notable limits |
| --- | --- | --- | --- |
| **OpenAI** | JSONL file uploaded through the Files API | OpenAI file storage | 50,000 requests or 200 MB per batch; 24-hour window |
| **Anthropic** | Inline list of requests in the create call | None required | 100,000 requests or 256 MB per batch; most finish within an hour; 24-hour expiry |
| **Amazon Bedrock** | JSONL records in Amazon S3 | S3 input and output locations | Model invocation jobs configured per model and Region |
| **Google Gemini** | Uploaded file or inline requests | Gemini file storage | Model named on the batch job |

Anthropic's [Message Batches documentation](https://platform.claude.com/docs/en/build-with-claude/batch-processing) covers the Claude batch API in detail, including the 29-day window for downloading results.

For setup of each provider in Bifrost, see the guides for [Anthropic](https://www.getmaxim.ai/bifrost/guides/providers/anthropic), [Bedrock](https://www.getmaxim.ai/bifrost/guides/providers/bedrock), and [Gemini](https://www.getmaxim.ai/bifrost/guides/providers/gemini).

## Running Batch Jobs Across Providers with Bifrost

Bifrost supports the OpenAI Files API and Batch API with cross-provider routing. Applications keep the OpenAI SDK, point it at the Bifrost `/openai` endpoint, and name the provider per request. Bifrost handles each provider's storage and input format, so the same workflow submits batch jobs to OpenAI, Anthropic, Bedrock, or Gemini.

![The OpenAI SDK points at Bifrost, which routes files and batch calls to OpenAI native storage, Bedrock with S3, Anthropic inline requests, or Gemini native storage](https://articles-images-cdn.t3.tigrisfiles.io/diagrams/openai-batch-api/batch-bifrost-routing.png)

The OpenAI SDK points at Bifrost, which routes files and batch calls to OpenAI native storage, Bedrock with S3, Anthropic inline requests, or Gemini native storage

*Figure 3: One OpenAI SDK workflow, with the provider chosen per request, covers batch jobs on OpenAI, Bedrock, Anthropic, and Gemini through Bifrost.*

Point the client at Bifrost:

```python
from openai import OpenAI

client = OpenAI(
    base_url="<http://localhost:8080/openai>",
    api_key="sk-bf-your-virtual-key",
)
```

For OpenAI, upload and create as usual, adding the provider in `extra_body`:

```python
batch_file = client.files.create(
    file=open("batch_input.jsonl", "rb"),
    purpose="batch",
    extra_body={"provider": "openai"},
)

batch = client.batches.create(
    input_file_id=batch_file.id,
    endpoint="/v1/chat/completions",
    completion_window="24h",
    extra_body={"provider": "openai"},
)
```

For Anthropic, which batches inline, pass the requests directly with no file upload:

```python
requests = [
    {"custom_id": "ticket-001",
     "params": {"model": "claude-sonnet-4-5", "max_tokens": 50,
                "messages": [{"role": "user", "content": "Classify: login fails after reset"}]}},
]

batch = client.batches.create(
    input_file_id="",
    endpoint="/v1/chat/completions",
    completion_window="24h",
    extra_body={"provider": "anthropic", "requests": requests},
)
```

Provider notes from the [OpenAI SDK files and batch guide](https://docs.getbifrost.ai/integrations/openai-sdk/files-and-batch):

- **OpenAI and Gemini** use their native file storage; Gemini also takes the `model` in `extra_body`.
- **Bedrock** needs a `storage_config` for S3 on upload and an `output_s3_uri` on batch creation.
- **Anthropic** does not support file-based batches through this route; use inline `requests`.

Teams on native SDKs can use the [Anthropic SDK batch guide](https://docs.getbifrost.ai/integrations/anthropic-sdk/files-and-batch), the [Bedrock SDK batch guide](https://docs.getbifrost.ai/integrations/bedrock-sdk/files-and-batch), or the [GenAI SDK batch guide](https://docs.getbifrost.ai/integrations/genai-sdk/files-and-batch) instead.

## Governing Batch Traffic at the Gateway

Batch jobs can move more tokens in an hour than an application sends in a week, so they deserve the same access and spend controls as live traffic. Running them through a gateway ties every batch to an owner, keeps provider keys out of scripts, and puts bulk usage in the same logs as everything else.

Controls that apply to batch traffic in Bifrost:

- **Virtual keys.** Each team or pipeline uses its own [virtual key](https://docs.getbifrost.ai/features/governance/virtual-keys) instead of a raw provider key.
- **Model restrictions.** Keys that restrict models need care with file-based batches: on OpenAI and Azure the key must allow every model of the provider, and on Gemini, Vertex, and Bedrock the request must name an allowed `model`.
- **Budgets.** [Budgets and rate limits](https://docs.getbifrost.ai/features/governance/budget-and-limits) cap what a key can spend, with daily, weekly, monthly, quarterly, or yearly resets.
- **Central provider keys.** Provider credentials live in Bifrost, so rotating an OpenAI or Anthropic key does not touch every batch script.

Visibility and data handling:

- **One log.** Batch operations appear in [Bifrost request logs](https://docs.getbifrost.ai/features/observability/default) alongside synchronous calls.
- **Data stays in your environment.** Bifrost runs self-hosted, and no prompts, responses, or files leave the customer's infrastructure except to the providers you call.

The guide to [API key management for LLM applications](https://www.getmaxim.ai/articles/api-key-management-for-llm-applications/) covers credential hygiene in more depth.

## Batch API Best Practices

Batch jobs fail in predictable ways: malformed lines, files over the size limit, unsupported models, and jobs that expire because too much was queued at once. A few habits prevent most of these and make results easier to use.

- **Validate every line** before upload; one malformed line can fail the whole file.
- **Use meaningful `custom_id` values**, such as record IDs, so results join back to source data.
- **Split large jobs** into files under the request and size limits, and stagger creation to stay under enqueued-token caps.
- **Handle partial results.** Read both the output and error files, and resubmit failed lines in a new batch.
- **Pin model versions** in each line so a batch run is reproducible.
- **Keep synchronous fallbacks** for urgent work; [retries and fallbacks](https://docs.getbifrost.ai/features/retries-and-fallbacks) in Bifrost cover live traffic when a provider is degraded.
- **Check provider health** before launching large jobs with the [provider status page](https://www.getmaxim.ai/provider-status).

For multi-provider setups, the [multi-provider AI gateway comparison](https://www.getmaxim.ai/articles/top-multi-provider-ai-gateways-for-openai-anthropic-bedrock/) and the list of [LLM API providers](https://www.getmaxim.ai/articles/llm-api-providers/) cover the landscape.

## Batch Inference vs Other Cost and Throughput Tools

Batch inference is one of several ways to lower model cost and protect rate limits, and it combines well with the others. Choosing the right one depends on whether the workload is live, repetitive, or bulk.

| Technique | Best for | Latency | How it saves |
| --- | --- | --- | --- |
| **Batch API** | Bulk, independent, non-urgent jobs | Minutes to 24 hours | Discounted batch pricing and separate limits |
| **Semantic caching** | Repeated or similar live requests | Lower than a provider call | Skips the provider call on a cache hit |
| **Provider prompt caching** | Long shared prefixes | Same or lower | Cheaper reads of cached input tokens |
| **Model routing** | Mixed-difficulty live traffic | Same | Sends simple requests to cheaper models |

Bifrost supports [semantic caching](https://docs.getbifrost.ai/features/semantic-caching) and [routing rules](https://docs.getbifrost.ai/providers/routing-rules) for live traffic, and the [roundup of gateways with semantic caching](https://www.getmaxim.ai/articles/top-5-ai-gateways-with-semantic-caching-to-reduce-openai-and-anthropic-api-costs/) compares options.

## Frequently Asked Questions

### What is the OpenAI Batch API?

The OpenAI Batch API is an asynchronous endpoint for processing many independent requests in one job. You upload a JSONL file of requests, create a batch with a 24-hour completion window, and download a results file when it finishes. Batch usage is billed at 50% of synchronous pricing and uses a separate rate-limit pool.

### How long does an OpenAI batch take?

Each batch completes within 24 hours and often much sooner, depending on size and load. If a batch has not finished within 24 hours, it expires: unfinished requests are cancelled and completed results remain available in the output file.

### What are the OpenAI Batch API limits?

A batch can include up to 50,000 requests in an input file of up to 200 MB, and embedding batches are capped at 50,000 inputs. Organizations can create up to 2,000 batches per hour, and each model has a cap on enqueued tokens across active batches.

### Is there a Claude batch API?

Yes. Anthropic's Message Batches API accepts up to 100,000 requests or 256 MB per batch, sent inline rather than as an uploaded file, with most batches finishing within an hour and a 24-hour expiry. Through Bifrost, the same OpenAI SDK can submit Claude batches by setting the provider to Anthropic, as the [OpenAI SDK batch guide](https://docs.getbifrost.ai/integrations/openai-sdk/files-and-batch) shows.

### Can I use one SDK for batch jobs on several providers?

Yes. Bifrost supports the OpenAI Files and Batch APIs with cross-provider routing, so the OpenAI SDK can submit batch jobs to OpenAI, Anthropic, Bedrock, or Gemini by naming the provider per request. Bedrock needs S3 storage settings, and Anthropic uses inline requests.

### What is the difference between batch inference and real-time inference?

Real-time inference returns each response in seconds for a user or system that is waiting. Batch inference processes many requests asynchronously over minutes to hours, usually at lower cost and with separate rate limits. Most production systems use both: real-time for user-facing calls, batch for evaluations and bulk processing.

## Run Batch Jobs Anywhere from One Workflow

The OpenAI Batch API is the right tool whenever volume matters more than latency, and the same pattern exists on every major provider. Bifrost gives teams one OpenAI-compatible batch workflow across OpenAI, Anthropic, Bedrock, and Gemini, with keys, budgets, and logs applied to every job. To see it with your workloads, [book a demo](https://www.getmaxim.ai/book-a-demo) with the Bifrost team.

## Read next

[![Tokenmaxxing: What It Means and How to Govern AI Token Spend](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/tokenmaxxing-what-it-means-and-how-to-govern-ai-token-spend-bifrost-1920x1080.png) Tokenmaxxing is the practice of treating AI token consumption as a proxy for productivity. This guide explains where the term came from, why usage leaderboards backfired, what engineering leaders measure instead, and how to govern token spend with budgets, attribution, and routing.](https://www.getmaxim.ai/articles/tokenmaxxing/)

[![9 Best Self-Hosted AI Tools for Enterprise Teams](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/9-best-self-hosted-ai-tools-for-enterprise-teams-bifrost-1920x1080@2x.png) Self-hosted AI runs models, apps, and data services on infrastructure a team controls. This guide ranks nine tools by stack layer, including Bifrost, vLLM, Ollama, Open WebUI, and Qdrant, and shows how one gateway governs the whole stack.](https://www.getmaxim.ai/articles/self-hosted-ai-tools/)

[![7 Best Private AI Platforms for Regulated Enterprises](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/7-best-private-ai-platforms-for-regulated-enterprises-bifrost-1920x1080@2x.png) A private AI platform runs models and AI traffic inside infrastructure the organization controls. This guide ranks seven options, including Bifrost, NVIDIA AI Enterprise, Red Hat OpenShift AI, and Google Distributed Cloud air-gapped, on deployment, isolation, and governance.](https://www.getmaxim.ai/articles/private-ai-platforms/)

## More in AI Gateway

[![What Is a GenAI Gateway? How It Differs From an API Gateway](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/what-is-a-genai-gateway-how-it-differs-from-an-api-gateway-bifrost-1920x1080.png) A GenAI gateway is the control layer between applications and LLM providers, metering tokens and routing by model. This guide explains how it differs from a traditional API gateway, where each sits in the stack, and when a team needs both.](https://www.getmaxim.ai/articles/genai-gateway-vs-api-gateway/)

[![What Is LLMOps? A Practical Guide to Running LLMs in Production](https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w720/2026/11/what-is-llmops-a-practical-guide-to-running-llms-in-producti-bifrost-1920x1080.png) LLMOps is the practice of running large language model applications in production: choosing models, managing prompts, evaluating output, and controlling cost, reliability, and risk. This guide covers LLMOps vs MLOps, the lifecycle, the platform stack, and the gateway layer.](https://www.getmaxim.ai/articles/what-is-llmops/)

```json
{
    "@context": "https://schema.org",
    "@type": "Article",
    "publisher": {
        "@type": "Organization",
        "name": "Maxim Articles",
        "url": "https://www.getmaxim.ai/articles/",
        "logo": {
            "@type": "ImageObject",
            "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w256h256/2025/08/thumbnail.png",
            "width": 60,
            "height": 60
        }
    },
    "author": {
        "@type": "Person",
        "name": "Kuldeep Paul",
        "image": {
            "@type": "ImageObject",
            "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/2025/08/1727978381919.jpeg",
            "width": 800,
            "height": 800
        },
        "url": "https://www.getmaxim.ai/articles/author/kuldeep/",
        "sameAs": []
    },
    "headline": "OpenAI Batch API: A Practical Guide to Batch Inference Across Providers",
    "url": "https://www.getmaxim.ai/articles/openai-batch-api/",
    "datePublished": "2026-11-17T01:55:00.000Z",
    "dateModified": "2026-11-21T01:56:17.000Z",
    "image": {
        "@type": "ImageObject",
        "url": "https://storage.ghost.io/c/84/03/8403f2f6-141c-411a-8f55-a32d4291533e/content/images/size/w1200/2026/11/openai-batch-api-a-practical-guide-to-batch-inference-across-bifrost-1920x1080.png",
        "width": 1200,
        "height": 675
    },
    "keywords": "AI Gateway",
    "description": "The OpenAI Batch API runs thousands of requests asynchronously with a 24-hour turnaround and separate rate limits. This guide covers the JSONL format, limits, job lifecycle, and code, and how to run the same batch workflow on Claude, Bedrock, and Gemini through one gateway.",
    "mainEntityOfPage": "https://www.getmaxim.ai/articles/openai-batch-api/"
}
```
