Claude Platform Docs

批处理

创建消息批次
$client->messages->batches->create(list<Request> requests, ?string userProfileID, ?string workspaceID): MessageBatch
POST/v1/messages/batches

发送一批消息创建请求。

检索消息批次
$client->messages->batches->retrieve(string messageBatchID, ?string workspaceID): MessageBatch
GET/v1/messages/batches/{message_batch_id}

此端点是幂等的,可用于轮询消息批次是否完成。要访问消息批次的结果,请向响应中的 results_url 字段发起请求。

列出消息批次
$client->messages->batches->list(?string afterID, ?string beforeID, ?int limit, ?string workspaceID): Page<MessageBatch>
GET/v1/messages/batches

列出工作区内的所有消息批次。最近创建的批次最先返回。

取消消息批次
$client->messages->batches->cancel(string messageBatchID, ?string workspaceID): MessageBatch
POST/v1/messages/batches/{message_batch_id}/cancel

批次可在处理结束前的任何时间取消。一旦发起取消,批次将进入 canceling 状态,此时系统可能会先完成任何正在进行的、不可中断的请求,然后再最终完成取消。

删除消息批次
$client->messages->batches->delete(string messageBatchID, ?string workspaceID): DeletedMessageBatch
DELETE/v1/messages/batches/{message_batch_id}

删除消息批次。

检索消息批次结果
$client->messages->batches->results(string messageBatchID, ?string workspaceID): MessageBatchIndividualResponse
GET/v1/messages/batches/{message_batch_id}/results

.jsonl 文件的形式流式传输消息批次的结果。

Models
class DeletedMessageBatch { $type = 'message_batch_deleted'; $id; }
"message_batch_deleted" type

Deleted object type.

For Message Batches, this is always "message_batch_deleted".

string id

ID of the Message Batch.

class MessageBatch { $type = 'message_batch'; $id; $archivedAt; /* 7 more */ }
"message_batch" type

Object type.

For Message Batches, this is always "message_batch".

string id

Unique object identifier.

The format and length of IDs may change over time.

?\Datetime archivedAt

RFC 3339 datetime string representing the time at which the Message Batch was archived and its results became unavailable.

?\Datetime cancelInitiatedAt

RFC 3339 datetime string representing the time at which cancellation was initiated for the Message Batch. Specified only if cancellation was initiated.

\Datetime createdAt

RFC 3339 datetime string representing the time at which the Message Batch was created.

?\Datetime endedAt

RFC 3339 datetime string representing the time at which processing for the Message Batch ended. Specified only once processing ends.

Processing ends when every request in a Message Batch has either succeeded, errored, canceled, or expired.

\Datetime expiresAt

RFC 3339 datetime string representing the time at which the Message Batch will expire and end processing, which is 24 hours after creation.

ProcessingStatus processingStatus

Processing status of the Message Batch.

MessageBatchRequestCounts requestCounts

Tallies requests within the Message Batch, categorized by their status.

Requests start as processing and move to one of the other statuses only once processing of the entire batch ends. The sum of all values always matches the total number of requests in the batch.

?string resultsURL

URL to a .jsonl file containing the results of the Message Batch requests. Specified only once processing ends.

Results in the file are not guaranteed to be in the same order as requests. Use the custom_id field to match results to requests.

class MessageBatchCanceledResult { $type = 'canceled'; }
"canceled" type
class MessageBatchErroredResult { $type = 'errored'; $error; }
"errored" type
ErrorResponse error
class MessageBatchExpiredResult { $type = 'expired'; }
"expired" type
class MessageBatchIndividualResponse { $customID; $result; }
string customID

Developer-provided ID created for each request in a Message Batch. Useful for matching results to requests, as results may be given out of request order.

Must be unique for each request within the Message Batch.

Processing result for this request.

Contains a Message output if processing was successful, an error response if processing failed, or the reason why processing was not attempted, such as cancellation or expiration.

class MessageBatchRequestCounts { $canceled; $errored; $expired; /* 2 more */ }
int canceled

Number of requests in the Message Batch that have been canceled.

This is zero until processing of the entire Message Batch has ended.

int errored

Number of requests in the Message Batch that encountered an error.

This is zero until processing of the entire Message Batch has ended.

int expired

Number of requests in the Message Batch that have expired.

This is zero until processing of the entire Message Batch has ended.

int processing

Number of requests in the Message Batch that are processing.

int succeeded

Number of requests in the Message Batch that have completed successfully.

This is zero until processing of the entire Message Batch has ended.

One of the following:
class MessageBatchSucceededResult { $type = 'succeeded'; $message; }
"succeeded" type
Message message