← Blog

Claude API Batch Processing Jobs Tutorial

2026-11-15 · 5 min read · SubToAPI Team

What batch processing means for the Claude API

If you're searching for this, you probably have hundreds or thousands of prompts to run — classifying support tickets, summarizing documents, generating product descriptions — and you don't want to fire them one-by-one through synchronous requests. Batch processing is the pattern of submitting many requests together, letting them run asynchronously, and collecting the results once they're done instead of blocking on each call.

This tutorial walks through how to structure a batch job against the Claude API, how polling and result retrieval typically work, how to handle partial failures, and how to think about concurrency and rate limits so your job finishes reliably instead of falling over halfway through.

Why you shouldn't just loop synchronous calls

The naive approach is a for loop that calls the API once per item and waits for the response before moving to the next one. This works for 10 items. It falls apart at 1,000:

A proper batch job treats each request as an independent unit of work with its own ID, tracks state, and processes many in parallel (bounded by a concurrency limit), with retries built in.

Structuring a batch job

The core building blocks of any batch pipeline are the same regardless of which API you're hitting:

  1. A queue of work items, each with a unique ID and the input data needed to build the prompt.
  2. A worker pool that pulls items off the queue and sends requests, respecting a concurrency ceiling.
  3. A results store (a database table, a JSON file, a CSV) where each completed item is written as soon as it finishes — not at the end.
  4. A retry mechanism for transient failures (timeouts, 429s, 5xxs).
  5. A completion check so you know when the whole batch is done and can see which items failed.

Here's a minimal Node.js worker pool pattern that sends concurrent requests with a limit, using the Claude API directly:

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

async function processItem(item) {
  const response = await client.messages.create({
    model: "claude-opus-4-20250514",
    max_tokens: 500,
    messages: [{ role: "user", content: item.prompt }],
  });
  return { id: item.id, output: response.content[0].text };
}

async function runBatch(items, concurrency = 5) {
  const results = [];
  const queue = [...items];

  async function worker() {
    while (queue.length) {
      const item = queue.shift();
      try {
        const result = await processItem(item);
        results.push(result);
      } catch (err) {
        results.push({ id: item.id, error: err.message });
      }
    }
  }

  await Promise.all(Array.from({ length: concurrency }, worker));
  return results;
}

This runs 5 requests at a time, keeps going even if individual items fail, and collects everything into a results array you can write to disk or a database once the batch finishes.

Handling rate limits and retries

Batch jobs hit rate limits by design — that's the whole point of running many requests close together. Build retry logic with exponential backoff around 429 and 5xx responses instead of letting a single throttled request kill the job:

async function withRetry(fn, maxAttempts = 5) {
  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
    try {
      return await fn();
    } catch (err) {
      const status = err.status;
      if (attempt === maxAttempts || (status !== 429 && status < 500)) {
        throw err;
      }
      const delay = Math.min(1000 * 2 ** attempt, 30000);
      await new Promise((resolve) => setTimeout(resolve, delay));
    }
  }
}

Wrap each call to processItem with withRetry. Also lower your concurrency if you're seeing consistent 429s — it's cheaper to run slightly slower than to burn retries.

Persisting progress so you can resume

For jobs with thousands of items, write each completed result to persistent storage immediately, not just to an in-memory array. If the process dies at item 4,200 of 10,000, you want to restart and skip the 4,200 already done rather than re-run (and re-pay for) them.

A simple pattern: before processing an item, check if its ID already exists in your results table. If it does, skip it. This makes the whole job idempotent and safely resumable.

const done = new Set(await loadCompletedIds());
const pending = items.filter((item) => !done.has(item.id));

Where SubToAPI fits into a batch pipeline

If you're already using Claude through a personal or team subscription rather than a direct Anthropic API key, you don't have programmatic access to run batch jobs like this at all — subscriptions are built for chat UIs, not for scripts. SubToAPI turns that subscription into a standard HTTPS API with application keys (sub_live_...), so the same worker-pool pattern above works unchanged — you just point your requests at https://api.subtoapi.app/v1/messages with Authorization: Bearer $SUBTOAPI_KEY.

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-opus-4-20250514",
    "max_tokens": 500,
    "messages": [{"role": "user", "content": "Summarize this ticket: ..."}]
  }'

This is useful for teams running occasional large batch jobs (document processing, data labeling, content generation) who want per-request usage metadata without managing separate API billing — see the pricing page for plan details and the quickstart to get your key. Full request/response details are in the messages docs.

Monitoring and validating output

Don't treat a finished batch as a trusted batch. Once the job completes:

questions

Can I run truly asynchronous "fire and forget" batch jobs with the Claude API? The pattern described here is client-managed concurrency — your own code controls the worker pool, retries, and result storage. There's no server-side job queue you submit to and walk away from; you manage the lifecycle in your script or service.

How many requests can I run concurrently? It depends on your account's rate limits (requests per minute and tokens per minute). Start with a modest concurrency (3–5) and increase gradually while watching for 429 responses, rather than guessing a high number upfront.

What's the best way to handle partial failures in a large batch? Write results to persistent storage as each item completes, track completed IDs, and make reprocessing idempotent by skipping already-done items. This lets you safely re-run just the failed subset instead of restarting the entire job.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →