الانتقال إلى المحتوى
Claude وأدوات الـ AI للبرمجةClaude API و Tool Use· 7 دقائق للقراءة

Thousands of Requests? Batch Them Instead of Racing the Rate Limit

Parallel calls pay full price and compete with production for the same limits. The Message Batches API halves the bill and runs on its own limits.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • Claude API
محتويات المقال

The support team adopts a new ticket taxonomy and asks you to relabel last year's 40,000 tickets with Claude Opus 5.5. You write an asyncio script with 50 concurrent requests, tuned to sit just under your organization's rate limit, and start it after lunch. By three o'clock the customer-facing support chat, running on the same model in the same organization, is answering some users with errors: 429s that weren't there in the morning. The script finishes in the evening, and the invoice shows every token at full price.

The common misconception

"The fastest and cheapest way to process thousands of documents is firing parallel requests as fast as rate limits allow." It's how most of us scale any API client:

  • More concurrency means more throughput, and the rate limit looks like the only ceiling.
  • The SDK already retries 429s with backoff, so pushing right up against the limit feels safe.
  • "Batch API" sounds like an overnight job from another era, slow by design.
  • A parallel script shows progress immediately, and you can stop it the moment something looks wrong.

The half-truth: for a few hundred requests that a user is waiting on, parallel calls are the right tool. For thousands of requests that nobody reads until tomorrow, they cost twice what they need to and compete with your production traffic for the same limits.

What actually happens

Parallel calls share everything with production

are set at the organization level and measured per model class. A bulk script and your live product calling the same model draw from the same requests-per-minute and tokens-per-minute budget. Tune the script to "just under the limit" and there's nothing left for real users, and the SDK's automatic retries only add attempts. Every one of those requests is billed at the standard price: $4 per million input tokens and $20 per million output tokens on Claude Opus 5.5.

A batch is one asynchronous job

A is a list of ordinary Messages requests, each with a custom_id and the usual params, processed asynchronously "with each request handled independently". The docs' numbers:

  • Size: up to 100,000 requests or 256 MB per batch, whichever comes first.
  • Price: all usage at 50% of standard prices, which makes Claude Opus 5.5 $2 input and $10 output per million tokens. The discount covers input, output and "any special tokens".
  • Time: most batches complete within an hour. Results are available when every request has finished or after 24 hours, and requests not processed by then expire.
  • Limits: batches have their own rate limits, and "Usage of the Batches API does not affect rate limits in the Messages API."
  • Retention: results stay downloadable for 29 days after the batch is created.

So the honest comparison isn't "fast versus slow". It's "seconds per answer at full price, competing with production" versus "an hour or so for the whole set at half price, on separate limits". Batches can even go further than the synchronous API: with the output-300k-2026-03-24 beta header, a batched Claude Opus 5.5 request can set max_tokens up to 300,000, where the synchronous limit is 128K.

Each request gets its own result

When processing_status turns ended, every request has one of four results: succeeded with the message, errored, canceled or expired. You aren't billed for the last three. An errored result with an invalid_request_error needs a fixed request; other errors can be resent as they are. One failure doesn't affect the other requests in the batch.

Relabeling the tickets

The first version races the rate limit. The second submits one batch and goes on with the day:

Python relabel.py
import asyncioimport anthropicclient = anthropic.AsyncAnthropic()limit = asyncio.Semaphore(50)  # tuned to sit just under our rate limitasync def label(ticket: dict) -> str:    async with limit:        reply = await client.messages.create(            model="claude-opus-5-5", max_tokens=256,            messages=[{"role": "user", "content": prompt_for(ticket)}],        )    return next(b.text for b in reply.content if b.type == "text")async def main():    labels = await asyncio.gather(*(label(t) for t in TICKETS))    print(len(labels), "labels, every token at the standard price")asyncio.run(main())

Once the batch has ended, a second job reads the results:

Python collect.py
labels, to_fix, to_resend = {}, [], []for item in client.messages.batches.results(BATCH_ID):    ticket_id = item.custom_id.removeprefix("ticket-")    result = item.result    if result.type == "succeeded":        blocks = result.message.content        labels[ticket_id] = next(b.text for b in blocks if b.type == "text")    elif result.type == "errored" and \            result.error.error.type == "invalid_request_error":        to_fix.append(ticket_id)  # resending it unchanged fails again    else:  # other errors, canceled, expired: resend as they are        to_resend.append(ticket_id)print(len(labels), len(to_fix), len(to_resend))  # labeled, fix, resend
Parallel Messages API callsMessage Batches API
PriceStandard50% of standard, on all usage
Time to resultsSeconds per requestMost batches within 1 hour, at most 24 hours
Rate limitsShared with your live trafficSeparate, and don't affect the Messages API
FailuresYour retry codeA result per request; errored, canceled and expired aren't billed
Not available—stream, fast mode speed, fallbacks, max_tokens: 0

How to apply it in your project

  1. Sort your workloads by who's waitingAnything a user waits on stays on the Messages API. Evaluations, backfills, nightly summaries and bulk classification are batch candidates.
  2. Dry-run one requestSend a single request through the Messages API first, as the docs suggest, so a validation error doesn't come back 100,000 times.
  3. Design the custom_idUse an ID you can map back to your data, such as ticket-1042, and never rely on result order.
  4. Handle every result typeFix invalid_request_error requests, resend the other failures and expired ones, and keep the results within 29 days.
  5. Watch the 24-hour windowSplit very large jobs into several batches, and check request_counts so expirations don't go unnoticed.

Key takeaways

  • Parallel requests pay full price and share your organization's rate limits with production.
  • The Message Batches API bills all usage at 50% of standard prices and has its own rate limits.
  • Most batches finish within an hour, but plan for up to 24 hours: batches are for work nobody waits on.
  • Results arrive in any order; match them by custom_id, never by position.
  • Errored, canceled and expired requests aren't billed, but they still need your code to fix or resend them.

📚 المصادر

  1. Batch processing — Claude API Docs
  2. Create a Message Batch — Claude API Reference
  3. Pricing: Batch processing — Claude API Docs
  4. Rate limits — Claude API Docs

التعليقات (0)