Создать пакет сообщений
POST/v1/messages/batches
Отправьте пакет запросов на создание сообщений.
Message Batches API можно использовать для одновременной обработки нескольких запросов Messages API. После создания пакета сообщений его обработка начинается немедленно. Обработка пакетов может занимать до 24 часов.
Подробнее о Message Batches API читайте в нашем руководстве пользователя
Parameters
Returns
Создать пакет сообщений
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
$client = new Client(apiKey: 'my-anthropic-api-key');
$messageBatch = $client->messages->batches->create(
requests: [
[
'customID' => 'my-custom-id-1',
'params' => [
'maxTokens' => 1024,
'messages' => [['content' => 'Hello, world', 'role' => 'user']],
'model' => Model::CLAUDE_OPUS_5,
'cacheControl' => ['type' => 'ephemeral', 'ttl' => '5m'],
'container' => [
'id' => 'id',
'skills' => [
['skillID' => 'pdf', 'type' => 'anthropic', 'version' => 'latest']
],
],
'inferenceGeo' => 'inference_geo',
'metadata' => ['userID' => '13803d75-b4b5-4c3e-b2a2-6f21399b021b'],
'outputConfig' => [
'effort' => 'low',
'format' => ['schema' => ['foo' => 'bar'], 'type' => 'json_schema'],
],
'serviceTier' => 'auto',
'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', '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,
],
],
],
userProfileID: 'anthropic-user-profile-id',
workspaceID: 'wrkspc_011CZkZaBF1tNoB5wlCeusgy',
);
var_dump($messageBatch);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"
}