Crear un lote de mensajes
POST/v1/messages/batches
Envía un lote de solicitudes de creación de mensajes.
La API de Message Batches puede usarse para procesar múltiples solicitudes de la API de Messages a la vez. Una vez creado un lote de mensajes, comienza a procesarse de inmediato. Los lotes pueden tardar hasta 24 horas en completarse.
Obtén más información sobre la API de Message Batches en nuestra guía de usuario
Parameters
Returns
Crear un lote de mensajes
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
$client = new Client(apiKey: 'my-anthropic-api-key');
$betaMessageBatch = $client->beta->messages->batches->create(
requests: [
[
'customID' => 'my-custom-id-1',
'params' => [
'maxTokens' => 1024,
'messages' => [
[
'content' => 'Hello, world',
'role' => 'user',
'clearAt' => 'next_user_message',
'outputConfig' => ['effort' => 'low'],
],
],
'model' => Model::CLAUDE_OPUS_5,
'cacheControl' => ['type' => 'ephemeral', 'ttl' => '5m'],
'compaction' => [
'type' => 'summarize', 'instructions' => 'instructions'
],
'container' => [
'id' => 'id',
'skills' => [
['skillID' => 'pdf', 'type' => 'anthropic', 'version' => 'latest']
],
],
'contextManagement' => [
'edits' => [
[
'type' => 'clear_tool_uses_20250919',
'clearAtLeast' => ['type' => 'input_tokens', 'value' => 0],
'clearToolInputs' => true,
'excludeTools' => ['string'],
'keep' => ['type' => 'tool_uses', 'value' => 0],
'trigger' => ['type' => 'input_tokens', 'value' => 1],
],
],
],
'diagnostics' => ['previousMessageID' => 'previous_message_id'],
'fallbackCreditToken' => 'x',
'fallbacks' => 'default',
'inferenceGeo' => 'inference_geo',
'mcpServers' => [
[
'name' => 'name',
'type' => 'url',
'url' => 'url',
'authorizationToken' => 'authorization_token',
'toolConfiguration' => [
'allowedTools' => ['string'], 'enabled' => true
],
],
],
'metadata' => ['userID' => '13803d75-b4b5-4c3e-b2a2-6f21399b021b'],
'outputConfig' => [
'effort' => 'low',
'format' => ['schema' => ['foo' => 'bar'], 'type' => 'json_schema'],
'taskBudget' => [
'total' => 1024, 'type' => 'tokens', 'remaining' => 0
],
],
'outputFormat' => [
'schema' => ['foo' => 'bar'], 'type' => 'json_schema'
],
'serviceTier' => 'auto',
'speed' => 'standard',
'stopSequences' => ['string'],
'stream' => false,
'system' => [
[
'text' => 'Today\'s date is 2024-06-01.',
'type' => 'text',
'cacheControl' => ['type' => 'ephemeral', 'ttl' => '5m'],
'citations' => [
[
'citedText' => 'The grass is green. The sky is blue.',
'documentIndex' => 0,
'documentTitle' => 'x',
'endCharIndex' => 0,
'startCharIndex' => 0,
'type' => 'char_location',
],
],
],
],
'temperature' => 1,
'thinking' => [
'type' => 'adaptive',
'blockBinding' => [
'prefixMismatchBehavior' => BetaThinkingPrefixMismatchBehavior::ERROR,
],
'display' => 'summarized',
],
'toolChoice' => ['type' => 'auto', 'disableParallelToolUse' => true],
'tools' => [
[
'inputSchema' => [
'type' => 'object',
'properties' => ['location' => 'bar', 'unit' => 'bar'],
'required' => ['location'],
],
'name' => 'name',
'allowedCallers' => ['direct'],
'cacheControl' => ['type' => 'ephemeral', 'ttl' => '5m'],
'deferLoading' => true,
'description' => 'Get the current weather in a given location',
'eagerInputStreaming' => true,
'inputExamples' => [['foo' => 'bar']],
'strict' => true,
'type' => 'custom',
],
],
'topK' => 5,
'topP' => 0.7,
],
],
],
betas: [AnthropicBeta::MESSAGE_BATCHES_2024_09_24],
userProfileID: 'anthropic-user-profile-id',
workspaceID: 'wrkspc_011CZkZaBF1tNoB5wlCeusgy',
);
var_dump($betaMessageBatch);Response 200
{
"id": "msgbatch_013Zva2CMHLNnXjNJJKqJ2EF",
"archived_at": "2024-08-20T18:37:24.100435Z",
"cancel_initiated_at": "2024-08-20T18:37:24.100435Z",
"created_at": "2024-08-20T18:37:24.100435Z",
"ended_at": "2024-08-20T18:37:24.100435Z",
"expires_at": "2024-08-20T18:37:24.100435Z",
"processing_status": "in_progress",
"request_counts": {
"canceled": 10,
"errored": 30,
"expired": 10,
"processing": 100,
"succeeded": 50
},
"results_url": "https://api.anthropic.com/v1/messages/batches/msgbatch_013Zva2CMHLNnXjNJJKqJ2EF/results",
"type": "message_batch"
}Returns Examples
Response 200
{
"id": "msgbatch_013Zva2CMHLNnXjNJJKqJ2EF",
"archived_at": "2024-08-20T18:37:24.100435Z",
"cancel_initiated_at": "2024-08-20T18:37:24.100435Z",
"created_at": "2024-08-20T18:37:24.100435Z",
"ended_at": "2024-08-20T18:37:24.100435Z",
"expires_at": "2024-08-20T18:37:24.100435Z",
"processing_status": "in_progress",
"request_counts": {
"canceled": 10,
"errored": 30,
"expired": 10,
"processing": 100,
"succeeded": 50
},
"results_url": "https://api.anthropic.com/v1/messages/batches/msgbatch_013Zva2CMHLNnXjNJJKqJ2EF/results",
"type": "message_batch"
}