Follow Discord
Sweep 22 Oct 2026 · 21:04Z Build v2.1.309 528 read Stable v2.1.308 Latest v2.1.309 Next v2.1.309 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

Message Batches API changedbuild-with-claude/batch-processing

Nearest release: v2.1.309, published 3 hours before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+150added
Lines−149removed
From line 317 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits25to this page, all time

The whole hunk

from line 317, old and new numbered
/
lines
from line 317
317317 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
318318 
319319 BatchCreateParams params = BatchCreateParams.builder()
320 .addRequest(
321 BatchCreateParams.Request.builder()
322 .customId("my-first-request")
323 .params(
324 BatchCreateParams.Request.Params.builder()
325 .model(Model.CLAUDE_OPUS_5_5)
326 .maxTokens(1024)
327 .addUserMessage("Hello, world")
328 .build()
329 )
330 .build()
331 )
332 .addRequest(
333 BatchCreateParams.Request.builder()
334 .customId("my-second-request")
335 .params(
336 BatchCreateParams.Request.Params.builder()
337 .model(Model.CLAUDE_OPUS_5_5)
338 .maxTokens(1024)
339 .addUserMessage("Hi again, friend")
340 .build()
341 )
342 .build()
343 )
344 .build();
320 .addRequest(
321 BatchCreateParams.Request.builder()
322 .customId("my-first-request")
323 .params(
324 BatchCreateParams.Request.Params.builder()
325 .model(Model.CLAUDE_OPUS_5_5)
326 .maxTokens(1024)
327 .addUserMessage("Hello, world")
328 .build()
329 )
330 .build()
331 )
332 .addRequest(
333 BatchCreateParams.Request.builder()
334 .customId("my-second-request")
335 .params(
336 BatchCreateParams.Request.Params.builder()
337 .model(Model.CLAUDE_OPUS_5_5)
338 .maxTokens(1024)
339 .addUserMessage("Hi again, friend")
340 .build()
341 )
342 .build()
343 )
344 .build();
345345 
346346 MessageBatch messageBatch = client.messages().batches().create(params);
347347 
from line 459
459459 
460460 ```bash CLI
461461 # Check the status; repeat until processing_status is "ended"
462 ant messages:batches retrieve \
463 --message-batch-id "$MESSAGE_BATCH_ID"
462 ant messages:batches retrieve --message-batch-id "$MESSAGE_BATCH_ID"
464463 ```
465464 
466465 ```python Python
from line 559
560559 
561560 ```php PHP
562561 $client = new Client();
563 $messageBatchId = getenv("MESSAGE_BATCH_ID");
562 $messageBatchId = getenv('MESSAGE_BATCH_ID');
564563 
565564 $messageBatch = null;
566565 while (true) {
from line 566
567566 $messageBatch = $client->messages->batches->retrieve(
568567 messageBatchID: $messageBatchId,
569568 );
570 if ($messageBatch->processingStatus === "ended") {
569 if ($messageBatch->processingStatus === 'ended') {
571570 break;
572571 }
573572 
from line 669
670669 
671670 // Automatically fetches more pages as needed
672671 for (MessageBatch messageBatch : client
673 .messages()
674 .batches()
675 .list(BatchListParams.builder().limit(20).build())
676 .autoPager()) {
677 System.out.println(messageBatch);
672 .messages()
673 .batches()
674 .list(BatchListParams.builder()
675 .limit(20)
676 .build())
677 .autoPager()) {
678 System.out.println(messageBatch);
678679 }
679680 ```
680681 
from line 715
714715 
715716<CodeGroup>
716717 ```bash cURL
717 # Streams the batch's .jsonl results, one result per line.
718 # Streams the batch's .jsonl results, one result on each line.
718719 # For per-result handling (retries, validation errors), use the Claude SDK.
719720 curl "https://api.anthropic.com/v1/messages/batches/msgbatch_01HkcTjaV5uDC8jWR4ZsDV8d/results" \
720721 -H "anthropic-version: 2023-06-01" \
from line 723
722723 ```
723724 
724725 ```bash CLI
725 # Prints one result per line, for example `{"custom_id":"test-1","result":{"type":"succeeded",…}}`.
726 # For per-result handling (retries, validation errors), use the SDK
726 # Prints one result on each line, for example `{"custom_id":"test-1","result":{"type":"succeeded",…}}`.
727 # For per-result handling (retries, validation errors), use the Claude SDK
727728 # examples in the other tabs.
728729 ant messages:batches results \
729730 --message-batch-id msgbatch_01HkcTjaV5uDC8jWR4ZsDV8d \
from line 836
835836 import com.anthropic.models.messages.batches.BatchResultsParams;
836837 import com.anthropic.models.messages.batches.MessageBatchIndividualResponse;
837838 // ...
838 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
839 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
839840 
840 // Stream results file in memory-efficient chunks, processing one at a time
841 try (
842 StreamResponse<MessageBatchIndividualResponse> streamResponse = client
843 .messages()
844 .batches()
845 .resultsStreaming(
846 BatchResultsParams.builder()
847 .messageBatchId("msgbatch_01HkcTjaV5uDC8jWR4ZsDV8d")
848 .build()
849 )
850 ) {
851 streamResponse
852 .stream()
853 .forEach(result -> {
854 switch (result.result().type().value()) {
855 case SUCCEEDED -> System.out.println("Success! " + result.customId());
856 case ERRORED -> {
857 if (result.result().asErrored().error().error().isInvalidRequestError()) {
858 // Request body must be fixed before re-sending request
859 System.out.println("Validation error: " + result.customId());
860 } else {
861 // Request can be retried directly
862 System.out.println("Server error: " + result.customId());
863 }
864 }
865 case EXPIRED -> System.out.println("Request expired: " + result.customId());
866 }
867 });
868 }
841 // Stream results file in memory-efficient chunks, processing one at a time
842 try (
843 StreamResponse<MessageBatchIndividualResponse> streamResponse = client
844 .messages()
845 .batches()
846 .resultsStreaming(
847 BatchResultsParams.builder()
848 .messageBatchId("msgbatch_01HkcTjaV5uDC8jWR4ZsDV8d")
849 .build()
850 )
851 ) {
852 streamResponse
853 .stream()
854 .forEach(result -> {
855 switch (result.result().type().value()) {
856 case SUCCEEDED -> System.out.println("Success! " + result.customId());
857 case ERRORED -> {
858 if (result.result().asErrored().error().error().isInvalidRequestError()) {
859 // Request body must be fixed before re-sending request
860 System.out.println("Validation error: " + result.customId());
861 } else {
862 // Request can be retried directly
863 System.out.println("Server error: " + result.customId());
864 }
865 }
866 case EXPIRED -> System.out.println("Request expired: " + result.customId());
867 }
868 });
869 }
869870 ```
870871 
871872 ```php PHP
from line 882
881882 echo "Success! {$result->customID}\n";
882883 break;
883884 case $result->result instanceof MessageBatchErroredResult:
884 if ($result->result->error->error->type === "invalid_request_error") {
885 if ($result->result->error->error->type === 'invalid_request_error') {
885886 echo "Validation error: {$result->customID}\n";
886887 } else {
887888 echo "Server error: {$result->customID}\n";
from line 988
987988 ```java Java
988989 import com.anthropic.models.messages.batches.*;
989990 // ...
990 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
991 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
991992 
992 MessageBatch messageBatch = client
993 .messages()
994 .batches()
995 .cancel("msgbatch_01HkcTjaV5uDC8jWR4ZsDV8d");
996 System.out.println(messageBatch);
993 MessageBatch messageBatch = client
994 .messages()
995 .batches()
996 .cancel("msgbatch_01HkcTjaV5uDC8jWR4ZsDV8d");
997 System.out.println(messageBatch);
997998 ```
998999 
9991000 ```php PHP
from line 1376
13751376 // ...
13761377 import com.anthropic.models.messages.batches.*;
13771378 // ...
1378 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
1379 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
13791380 
1380 BatchCreateParams createParams = BatchCreateParams.builder()
1381 .addRequest(
1382 BatchCreateParams.Request.builder()
1383 .customId("my-first-request")
1384 .params(
1385 BatchCreateParams.Request.Params.builder()
1386 .model(Model.CLAUDE_OPUS_5_5)
1387 .maxTokens(1024)
1388 .systemOfTextBlockParams(
1389 List.of(
1390 TextBlockParam.builder()
1391 .text(
1392 "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.\n"
1381 BatchCreateParams createParams = BatchCreateParams.builder()
1382 .addRequest(
1383 BatchCreateParams.Request.builder()
1384 .customId("my-first-request")
1385 .params(
1386 BatchCreateParams.Request.Params.builder()
1387 .model(Model.CLAUDE_OPUS_5_5)
1388 .maxTokens(1024)
1389 .systemOfTextBlockParams(
1390 List.of(
1391 TextBlockParam.builder()
1392 .text(
1393 "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.\n"
1394 )
1395 .build(),
1396 TextBlockParam.builder()
1397 .text("<the entire contents of Pride and Prejudice>")
1398 .cacheControl(CacheControlEphemeral.builder().build())
1399 .build()
1400 )
1401 )
1402 .addUserMessage("Analyze the major themes in Pride and Prejudice.")
1403 .build()
13931404 )
1394 .build(),
1395 TextBlockParam.builder()
1396 .text("<the entire contents of Pride and Prejudice>")
1397 .cacheControl(CacheControlEphemeral.builder().build())
13981405 .build()
1399 )
1400 )
1401 .addUserMessage("Analyze the major themes in Pride and Prejudice.")
1402 .build()
1403 )
1404 .build()
1405 )
1406 .addRequest(
1407 BatchCreateParams.Request.builder()
1408 .customId("my-second-request")
1409 .params(
1410 BatchCreateParams.Request.Params.builder()
1411 .model(Model.CLAUDE_OPUS_5_5)
1412 .maxTokens(1024)
1413 .systemOfTextBlockParams(
1414 List.of(
1415 TextBlockParam.builder()
1416 .text(
1417 "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.\n"
1406 )
1407 .addRequest(
1408 BatchCreateParams.Request.builder()
1409 .customId("my-second-request")
1410 .params(
1411 BatchCreateParams.Request.Params.builder()
1412 .model(Model.CLAUDE_OPUS_5_5)
1413 .maxTokens(1024)
1414 .systemOfTextBlockParams(
1415 List.of(
1416 TextBlockParam.builder()
1417 .text(
1418 "You are an AI assistant tasked with analyzing literary works. Your goal is to provide insightful commentary on themes, characters, and writing style.\n"
1419 )
1420 .build(),
1421 TextBlockParam.builder()
1422 .text("<the entire contents of Pride and Prejudice>")
1423 .cacheControl(CacheControlEphemeral.builder().build())
1424 .build()
1425 )
1426 )
1427 .addUserMessage("Write a summary of Pride and Prejudice.")
1428 .build()
14181429 )
1419 .build(),
1420 TextBlockParam.builder()
1421 .text("<the entire contents of Pride and Prejudice>")
1422 .cacheControl(CacheControlEphemeral.builder().build())
14231430 .build()
1424 )
1425 )
1426 .addUserMessage("Write a summary of Pride and Prejudice.")
1427 .build()
1428 )
1429 .build()
1430 )
1431 .build();
1431 )
1432 .build();
14321433 
1433 MessageBatch messageBatch = client.messages().batches().create(createParams);
1434 MessageBatch messageBatch = client.messages().batches().create(createParams);
14341435 ```
14351436 
14361437 ```php PHP
from line 1543
15421543 
15431544All [server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools) (web search, web fetch, code execution, MCP connectors, advisor, and tool search) work in batch requests. The batch worker runs the same server-side agentic loop as the synchronous Messages API.
15441545 
1545Because there is no open connection to maintain, the batch loop runs **more iterations per turn** than a synchronous request before it returns `stop_reason: "pause_turn"`. If a batch result comes back with `pause_turn`, the turn did not complete; you can continue it by submitting the paused assistant content in a follow-up request (batch or synchronous) exactly as shown in the [pause\_turn continuation pattern](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools#the-server-side-loop-and-pause-turn).
1546Because there is no open connection to maintain, the batch loop can run **more iterations in a turn** than a synchronous request before it returns `stop_reason: "pause_turn"`. If a batch result comes back with `pause_turn`, the turn did not complete; you can continue it by submitting the paused assistant content in a follow-up request (batch or synchronous) exactly as shown in the [pause\_turn continuation pattern](https://platform.claude.com/docs/en/agents-and-tools/tool-use/server-tools#the-server-side-loop-and-pause-turn).
15461547 
15471548The batch worker additionally throttles `web_search` for each organization so that highly concurrent batch processing does not exhaust your organization's web-search rate limit. The batch retries throttled requests automatically; you don't need to handle this yourself, but very large web-search batches might take longer to complete.
15481549 
from line 1716
17151716 import com.anthropic.models.beta.messages.batches.*;
17161717 
17171718 void main() {
1718 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
1719 AnthropicClient client = AnthropicOkHttpClient.fromEnv();
17191720 
1720 BatchCreateParams params = BatchCreateParams.builder()
1721 .addBeta("output-300k-2026-03-24")
1722 .addRequest(
1723 BatchCreateParams.Request.builder()
1724 .customId("long-form-request")
1725 .params(
1726 BatchCreateParams.Request.Params.builder()
1727 .model(Model.CLAUDE_OPUS_5_5)
1728 .maxTokens(300_000L)
1729 .addUserMessage("Write a comprehensive technical guide to building distributed systems, covering architecture patterns, consistency models, fault tolerance, and operational best practices.")
1730 .build()
1721 BatchCreateParams params = BatchCreateParams.builder()
1722 .addBeta("output-300k-2026-03-24")
1723 .addRequest(
1724 BatchCreateParams.Request.builder()
1725 .customId("long-form-request")
1726 .params(
1727 BatchCreateParams.Request.Params.builder()
1728 .model(Model.CLAUDE_OPUS_5_5)
1729 .maxTokens(300_000L)
1730 .addUserMessage("Write a comprehensive technical guide to building distributed systems, covering architecture patterns, consistency models, fault tolerance, and operational best practices.")
1731 .build()
1732 )
1733 .build()
17311734 )
1732 .build()
1733 )
1734 .build();
1735 .build();
17351736 
1736 BetaMessageBatch messageBatch = client.beta().messages().batches().create(params);
1737 BetaMessageBatch messageBatch = client.beta().messages().batches().create(params);
17371738 
1738 IO.println(messageBatch);
1739 IO.println(messageBatch);
17391740 }
17401741 ```
17411742 
Feedback