← LearnClaude API · Optimization

Claude API Bulk Sentiment Analysis Workflow: Batch Guide

To run bulk sentiment analysis with the Claude API, use the Message Batches API: package each review or ticket as a separate request with a unique ID, submit them all at once, and retrieve classified results asynchronously. This approach costs 50% less than standard API calls and handles up to 100,000 requests per batch.

What Is the Claude API Bulk Sentiment Analysis Workflow?

The fastest, most cost-effective way to classify large volumes of text with Claude is the Message Batches API. Instead of sending one request per review and waiting for each response, you package every classification task into a single grouped job, submit it once, and retrieve all results when processing completes. According to Anthropic's documentation, all batch requests are charged at 50% of standard API prices — meaning a 50,000-ticket sentiment job costs half what sequential real-time calls would.

This workflow is purpose-built for exactly this scenario: a company with tens of thousands of customer support tickets, product reviews, or survey responses that need sentiment labels before being loaded into a dashboard or analytics pipeline. The batch model is asynchronous, so your application doesn't block waiting for results — you submit, poll for completion, and download a structured results file.

How Does the Message Batches API Work for Sentiment Classification?

The core mechanic is straightforward. Each piece of text you want classified becomes one request object. You assign it a custom_id — a string you choose, like ticket-00042 — and pair it with a standard Messages API payload containing your classification prompt. All of these request objects are bundled into a list and submitted in a single API call.

Anthropic's infrastructure processes the batch asynchronously, typically completing within an hour (with a 24-hour maximum window). When processing finishes, results are available as a JSONL file — one JSON object per line — where each line contains the custom_id you assigned and the model's response. Because results are not guaranteed to be in submission order, the custom_id is how you match each classification back to its original ticket or review.

Results are stored for 29 days after batch creation, giving you a reasonable window to download and archive them.

How Do You Build a Bulk Sentiment Analysis Batch Step by Step?

  1. Install the SDK. Add the Anthropic Python or TypeScript SDK to your project, or plan to call the REST API directly with your API key.
  2. Build your request list. For each piece of text, create a request object with a unique custom_id and a params block containing your model choice, token limit, and a prompt like "Classify the following as positive, negative, or neutral: [text]".
  3. Submit the batch. Call the batch creation endpoint (or client.messages.batches.create() in the SDK), passing your full list of request objects. Save the batch ID returned in the response.
  4. Poll for completion. Periodically call the batch retrieval endpoint with your batch ID and check whether processing_status equals ended. A polling interval of 30–60 seconds is reasonable for large jobs.
  5. Download results. Once status is ended, stream or download the JSONL results file from the URL provided in the batch object.
  6. Match results to source records. Iterate over each line in the JSONL file, use the custom_id to join back to your original dataset, and extract the sentiment label from the model's text response.

What Does the Code Look Like for a Small Sentiment Batch?

Here's a minimal Python example classifying two reviews. The same pattern scales to tens of thousands of items:

import anthropic
import time

client = anthropic.Anthropic()

requests = [
    {
        "custom_id": "review-001",
        "params": {
            "model": "claude-sonnet-4-5-20250929",
            "max_tokens": 10,
            "messages": [{
                "role": "user",
                "content": "Classify as positive/negative/neutral: 'Fast shipping, love it!'"
            }]
        }
    },
    {
        "custom_id": "review-002",
        "params": {
            "model": "claude-sonnet-4-5-20250929",
            "max_tokens": 10,
            "messages": [{
                "role": "user",
                "content": "Classify as positive/negative/neutral: 'Broke after one day.'"
            }]
        }
    }
]

# Submit
batch = client.messages.batches.create(requests=requests)
batch_id = batch.id

# Poll
while True:
    status = client.messages.batches.retrieve(batch_id)
    if status.processing_status == "ended":
        break
    time.sleep(30)

# Retrieve results
for result in client.messages.batches.results(batch_id):
    label = result.result.message.content[0].text
    print(f"{result.custom_id}: {label}")

The output is a JSONL stream where each entry pairs your custom_id with the model's classification. At scale — say, 50,000 support tickets — this same loop handles the full dataset in a single batch submission.

When Should You Use Batch Processing vs. Real-Time API Calls?

The decision comes down to whether your workflow can tolerate an asynchronous turnaround. The Message Batches API is the right choice when all of the following are true: you have a large volume of independent requests, results don't need to appear in real time, and cost efficiency matters. Sentiment analysis on a historical ticket backlog is a textbook fit — no user is waiting for the label, and the job can run overnight.

Scenario Use Batch API Use Standard API
Classify 50,000 historical support tickets ✓ Async, 50% cost savings
Classify a ticket as a user submits it live ✓ Immediate response needed
Nightly sentiment pipeline for new reviews ✓ Scheduled, no latency requirement
Multi-turn conversation where each reply depends on the last ✓ Sequential dependency
Bulk re-labeling of archived data ✓ Large volume, independent requests
Streaming partial output to a UI as it generates ✓ Streaming not supported in batches

How Do You Maximize Cost Savings on a Sentiment Batch?

The 50% batch discount is the baseline, but it can be stacked with prompt caching. If all your classification requests share the same system prompt — for example, a detailed instruction block defining your sentiment taxonomy — you can add a cache control marker on that shared context. Requests that hit the cache pay reduced rates on the cached tokens, on top of the batch discount. For large-scale jobs where the system prompt is substantial, this combination can reduce costs significantly compared to real-time equivalents.

Keep your per-request token budget tight. Sentiment classification rarely needs more than a handful of output tokens — a single word like positive, negative, or neutral is the entire output. Setting a low token limit per request keeps each item cheap and speeds up batch processing.

What Are the Most Common Pitfalls in a Batch Sentiment Workflow?

  • Assuming result order matches submission order. It doesn't. Always use custom_id to join results back to your source data — never rely on positional indexing.
  • Exceeding batch size limits. Each batch has a maximum of 100,000 requests and a payload size ceiling. If your dataset is larger, split it into multiple batches and track each batch ID separately.
  • Not downloading results before expiry. Results are available for 29 days from batch creation. Build expiry awareness into any pipeline that might access results weeks after submission — download and archive promptly.
  • Skipping a test with a single synchronous call. Validation errors inside a batch can be hard to debug. Always test your request shape with a single standard Messages API call before wrapping it in a batch submission.
  • Not checking for errored items. Individual requests inside a batch can fail independently. After polling to completion, inspect the error counts in the batch status object and handle failed items — re-queue them or flag for manual review.

Is Batch Sentiment Analysis Worth It for Smaller Datasets?

Yes, even at small scale. The 50% cost reduction applies regardless of batch size — a batch of 100 reviews costs half what 100 sequential calls would. Beyond cost, batching establishes the correct architectural pattern: custom_id tracking, async polling, and JSONL result handling. When your dataset grows from hundreds to hundreds of thousands, the code changes minimally. Starting with the batch pattern from the beginning avoids a painful refactor later.

The only real trade-off is the asynchronous turnaround. If you need a sentiment label within milliseconds — for example, to display a real-time indicator as a customer types — the standard synchronous API is the right tool. For everything else, batching is almost always the better choice on both cost and operational simplicity.

Frequently asked questions

How long does a bulk sentiment analysis batch take to complete?

According to Anthropic's documentation, batch processing typically completes within an hour, with a 24-hour maximum window. For most sentiment analysis jobs, results are available well within that one-hour estimate.

How much does batch sentiment analysis cost compared to real-time API calls?

All Message Batches API requests are charged at 50% of standard API prices. This discount can also be stacked with prompt caching discounts if your requests share a large system prompt.

What is the maximum number of requests I can include in a single sentiment batch?

Each batch supports up to 100,000 requests. If your dataset is larger, split it into multiple batches and track each batch ID separately.

How do I match sentiment results back to the original tickets or reviews?

Results in the JSONL output file are not guaranteed to be in submission order. You must use the custom_id field you assigned to each request to match each result back to its original record.

Can I use the batch API for real-time sentiment classification in a live product?

No. The Message Batches API is designed for asynchronous workloads that can tolerate up to a one-hour turnaround. For live, user-facing sentiment classification, use the standard synchronous Messages API.

How long are batch results stored?

Results are stored for 29 days after batch creation. Download and archive your results promptly, and build expiry checks into any automated pipeline that might access results weeks after submission.

Go deeper

Batch processing is one of 85 features in Claude Master — the independent, continuously updated manual with worked examples, the pitfalls, and the workflows that put Claude to work.

Get Claude Master — founding price

Independent product. Not affiliated with or endorsed by Anthropic. "Claude" is a trademark of Anthropic, used here only to describe the subject of this guide.