← All news

News / Learn / Working with model APIs

When should you use batch requests?

You'll be able to decide when a batch request beats a live call, and submit and read one correctly.

A batch request sends many prompts to a model in one job. You submit the job, wait, and collect the results later. Nobody waits on each answer in real time. The provider runs the work when it has spare capacity, so the job costs less than the same calls made live.

Many product tasks do not need an answer right away. Tagging a backlog of support tickets, summarizing a night's uploads, or scoring a catalog can wait hours. Batch processing lets you pay less and avoid tight rate limits for that work. Choosing it for the right jobs keeps your interactive features fast and your bill lower.

A batch is a file of requests. Each line holds one complete request with its own ID, the model, and the messages. You upload the file, create a batch job that points at it, and the provider processes the lines asynchronously. Your code checks the job status until it finishes.

When the job completes, you download a results file. Each result line carries the ID you set, so you can match outputs to inputs even if they come back out of order. Some lines can fail while others succeed. Always check each result for an error before you use its output.

Use batches when latency does not matter: offline evaluations, bulk labeling, data cleaning, nightly reports, and embedding large document sets. Keep live calls for anything a user is waiting on, such as a chat reply or an autocomplete suggestion.

Batch pricing, turnaround windows, and size limits change over time. Read the current provider documentation before you plan a budget or a deadline.

A batch file in JSON Lines format. Each line is one independent request with a custom ID you use to match results.

{"custom_id": "ticket-001", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "your-model-name", "messages": [{"role": "system", "content": "Label the ticket as billing, bug, or other. Reply with the label only."}, {"role": "user", "content": "I was charged twice this month."}]}}
{"custom_id": "ticket-002", "method": "POST", "url": "/v1/chat/completions", "body": {"model": "your-model-name", "messages": [{"role": "system", "content": "Label the ticket as billing, bug, or other. Reply with the label only."}, {"role": "user", "content": "The export button crashes the app."}]}}

A short sketch to show the idea. Check the official docs of the tool you use.

  • Using batches for user-facing requests Keep batches for work nobody is waiting on. A user staring at a spinner needs a live call and streaming if the reply is long.
  • Assuming results come back in order Match each result to its input using custom_id. Do not rely on line position.
  • Ignoring per-line errors A batch can finish with some failed lines. Check each result for an error and retry only those requests.
  • Forgetting the job is asynchronous Store the batch ID, poll or wait for a completion signal, and handle expired or failed jobs in your pipeline.

Study idempotent job design, so a retried batch does not duplicate work. Also learn how to combine batches with evaluation pipelines and how to split large datasets into files within provider size limits.

Is a batch always cheaper?

Batch processing is typically priced below live calls for the same work, but check the provider's current pricing. Compare the total cost of your real workload before deciding.

How long until results arrive?

Batches run on a delayed schedule, not immediately. Read the provider's stated completion window and design your pipeline to tolerate waiting.

Can I mix models in one batch?

It depends on the provider. Many require one target endpoint per batch. Check the documentation for the rules that apply to you.

What happens if my job fails halfway?

Successful lines still produce output. Read the results file, keep the good outputs, and resubmit only the failed custom IDs.

Written with AI by CapyLaunch. Spotted a mistake? Email hello@capylaunch.com.