Sub topic 12
Comparing batch APIs across providers
This chapter assumes you can already run the OpenAI Batch API workflow from earlier chapters: write a JSONL file, submit it, poll it, and read the output and error files by custom_id. Here you will see how other providers' batch APIs differ from that workflow, and how to write your pipeline so the differences stay in one place.
Provider details change often. Treat the numbers below as examples of what to look for, and check each provider's current documentation for limits, prices, and field names before you build on them.
What stays the same
Every major batch offering follows the same contract.
- You submit many independent requests as one job.
- The provider processes them at its own pace, with no latency guarantee shorter than a completion window (usually up to 24 hours).
- You pay a reduced price, commonly about half the synchronous price. Verify the discount for your specific model.
- Each request carries an identifier you choose, and results come back in no guaranteed order.
- A job can finish with some requests succeeded and others failed, expired, or cancelled.
Because of this shared contract, the pipeline design from earlier chapters carries over: unique IDs, matching by ID, resubmitting only what is missing, and a small pilot before scaling.
Where they differ
The differences fall into five areas: how requests are submitted, how the job's status is reported, how results are returned, what limits apply, and how a partial failure shows up.
| Aspect | OpenAI Batch API | Anthropic Message Batches | Google Gemini Batch API | Amazon Bedrock batch inference |
|---|---|---|---|---|
| Input | Upload a JSONL file, then reference its file ID | Send requests in the body of the create call, as a list | Inline requests, or an uploaded JSONL file | JSONL file in an S3 bucket |
| Request ID field | `custom_id` | `custom_id` | `key` in file mode | `recordId` (optional) |
| Request shape | `method`, `url`, `body` | `params` (a normal Messages request) | `request` (a normal generate-content request) | `modelInput` (the model's native payload) |
| Status values | `validating`, `in_progress`, `finalizing`, `completed`, `failed`, `expired`, `cancelling`, `cancelled` | `in_progress`, `canceling`, `ended` | `JOB_STATE_PENDING`, `JOB_STATE_RUNNING`, `JOB_STATE_SUCCEEDED`, `JOB_STATE_FAILED`, `JOB_STATE_CANCELLED`, `JOB_STATE_EXPIRED` | `Submitted`, `Validating`, `Scheduled`, `InProgress`, `Completed`, `PartiallyCompleted`, `Failed`, `Stopped`, `Expired` |
| Results | Output file and separate error file | One results stream, one record per request | Inline responses or an output file | Output files written to S3 |
| Per-request outcome | HTTP status code in the record, or an error | `succeeded`, `errored`, `canceled`, or `expired` | A response or an error per key | A model output or an error per record |
Treat this table as a map of what to look up, not as a specification. Field names and status lists do change.
Submission: files versus inline
OpenAI and Bedrock make you stage a file first. OpenAI uses the Files API with purpose="batch". Bedrock reads from S3 and needs an IAM role that grants the service access to your input and output locations. Anthropic's original design sends the requests directly in the create call, which removes the upload step but makes the request body large. Gemini supports both: inline requests for small jobs, and a file for large ones.
The consequence for your code is that "submit" is not one operation everywhere. Sometimes it is one call, and sometimes it is upload, create, and permission setup.
Status: one terminal state or many
OpenAI reports a job as completed even when some requests failed. You find the failures in request_counts and the error file. Anthropic uses a single terminal status, ended, and the per-request outcome lives in the results. Bedrock adds PartiallyCompleted, which states the partial failure in the job status itself.
So you cannot decide "did this job succeed?" from the job status alone on any provider. Always inspect per-request results.
Results: where partial failure appears
On OpenAI, a failed request can show up in the error file, or in the output file with a non-200 status code. The third code example in this tutorial handles both. On Anthropic, every request produces one result record whose result.type tells you what happened. An expired result means the request did not run within the window, which is the same as a "missing" request in the OpenAI workflow but is reported explicitly.
Explicit reporting is easier to work with. You do not have to compute set(inputs) - set(results) - set(failed). You still should, as a check that nothing was dropped.
Limits
Each provider caps requests per job, file or payload size, and sometimes the number of jobs or tokens queued at once. Example values at the time of writing: OpenAI documents 50,000 requests and a 200 MB input file per batch. Anthropic documents 100,000 requests or 256 MB per batch, whichever is reached first. These values and the queue limits differ by model and account tier. Your chunking code should read its limits from configuration, not hard-code them.
Retention
Providers keep results for a limited time. Anthropic documents a retention period for results measured in weeks. Output files on OpenAI are files you can delete. Bedrock writes to your S3 bucket, so retention is yours to manage. Download and store results as soon as a job ends, and do not treat the provider as your archive.
Features that interact with batching
Check these per provider before assuming they work in batch mode:
- Prompt caching. Some providers apply cache discounts in batch jobs on a best-effort basis, since requests run in no fixed order.
- Streaming. Not applicable. Batch results are whole responses.
- Tool use and structured outputs. Usually supported, because the request body is the normal request, but confirm for each model.
- Discount stacking. Do not assume a batch discount combines with other discounts. Verify against the pricing page.
- Model availability. Not every model is offered in batch mode, and on Bedrock the choice depends on region.
Isolating the differences behind an adapter
The practical lesson is to keep provider-specific code at the edges. Your pipeline should work with a neutral record, and a small adapter per provider should translate to and from it.
The following script defines the neutral result record and two parsers. It runs without network access, because it parses sample lines in each provider's format.
import json
from dataclasses import dataclass
from typing import Optional
@dataclass
class Result:
id: str
ok: bool
text: Optional[str] = None
error: Optional[str] = None
def parse_openai_line(line: str) -> Result:
record = json.loads(line)
response = record.get("response")
if record.get("error") is None and response and response["status_code"] == 200:
content = response["body"]["choices"][0]["message"]["content"]
return Result(record["custom_id"], True, text=content)
return Result(record["custom_id"], False, error=str(record.get("error") or response))
def parse_anthropic_line(line: str) -> Result:
record = json.loads(line)
result = record["result"]
if result["type"] == "succeeded":
blocks = result["message"]["content"]
text = "".join(b["text"] for b in blocks if b["type"] == "text")
return Result(record["custom_id"], True, text=text)
# errored, canceled, or expired
return Result(record["custom_id"], False, error=result["type"])
openai_line = json.dumps({
"custom_id": "doc-001",
"response": {
"status_code": 200,
"body": {"choices": [{"message": {"content": "Meeting moved to Thursday."}}]},
},
"error": None,
})
anthropic_lines = [
json.dumps({
"custom_id": "doc-002",
"result": {
"type": "succeeded",
"message": {"content": [{"type": "text", "text": "Revenue grew 4%."}]},
},
}),
json.dumps({"custom_id": "doc-003", "result": {"type": "expired"}}),
]
results = [parse_openai_line(openai_line)]
results += [parse_anthropic_line(line) for line in anthropic_lines]
for r in results:
print(r)
expected = {"doc-001", "doc-002", "doc-003", "doc-004"}
print("missing:", expected - {r.id for r in results})
print("to retry:", sorted({r.id for r in results if not r.ok} | (expected - {r.id for r in results})))Running it prints three Result records, reports doc-004 as missing, and lists doc-003 and doc-004 as the IDs to retry. The retry rule is the same on every provider: anything not ok, plus anything absent, goes into the next job.
The request-building side is a mirror of this. A build_openai_file(tasks) function writes the method/url/body form. A build_anthropic_requests(tasks) function returns a list of {"custom_id": ..., "params": {...}} objects. Everything upstream and downstream of those two functions can stay unchanged.
Decision criteria
Often you do not choose a provider for its batch API. You choose a model, and the batch API comes with it. When you do have a choice, weigh these points.
- Turnaround. Both a one-hour typical turnaround and a full 24-hour window are normal. If your downstream job is time-sensitive, read what the provider says about typical completion, not only the maximum.
- Operational overhead. Bedrock needs S3 buckets and IAM roles, which suits teams already on AWS. A direct API with inline requests needs less setup for small jobs.
- Failure reporting. Explicit per-request outcomes reduce the code you write. File-based error reporting needs more reconciliation.
- Limits relative to your job size. If your typical job is 500,000 requests, per-batch caps decide how many chunks you create.
- Data location and retention. If results must stay in your own storage account, an S3-based design may fit better than provider-held results.
- Portability. If you may switch models, build the adapter layer from the start. The cost is small, and rewriting a pipeline later is large.
Common errors when moving between providers
- Treating the job status as success.
completed,ended, andCompletedall describe the job, not each request. - Reusing an OpenAI request body unchanged. The
urlandmethodfields are specific to OpenAI. Anthropic expectsparams, and Gemini expectsrequest. - Hard-coding limits from one provider into the chunking logic.
- Relying on line order. No provider guarantees it, so always match by ID.
- Forgetting to download results before they are deleted or expire.
- Ignoring that tokens are counted differently by different models, so cost estimates from one provider do not transfer.
Exercise
Your pipeline submits a job to Anthropic's Message Batches API. The job status is ended, and your results stream contains 980 records for 1,000 submitted requests. Of those, 950 are succeeded and 30 are expired. Which IDs do you resubmit, and why is checking for missing IDs still worth doing?
Show answer
Resubmit the 30 IDs whose result type is expired, plus the 20 IDs that have no record at all (1,000 minus 980). ended only means the job is over, not that every request succeeded. The 20 absent IDs show why you still compute a set difference between submitted and returned IDs: the per-request outcomes cover only the records you received, and a dropped or truncated download would otherwise go unnoticed.
Exercise
Why does the adapter in this chapter return a neutral Result record instead of letting the rest of the pipeline read each provider's raw response format?
Show answer
Provider formats differ in request shape, status values, and result layout. If the retry, storage, and reporting code read raw responses, every one of them would need provider-specific branches. With a neutral record, only the parse and build functions know about a provider, so switching or adding a provider means writing two small functions and leaving the rest unchanged.