Claude Platform Docs

批次

建立訊息批次
client.beta.messages.batches.create(params, options?): BetaMessageBatch
POST/v1/messages/batches

傳送一批訊息建立請求。

擷取訊息批次
client.beta.messages.batches.retrieve(messageBatchID, params?, options?): BetaMessageBatch
GET/v1/messages/batches/{message_batch_id}

此端點具冪等性,可用於輪詢訊息批次是否完成。若要存取訊息批次的結果,請對回應中的 results_url 欄位發出請求。

列出訊息批次
client.beta.messages.batches.list(params?, options?): Page<BetaMessageBatch>
GET/v1/messages/batches

列出工作區內的所有訊息批次。最近建立的批次會優先傳回。

取消訊息批次
client.beta.messages.batches.cancel(messageBatchID, params?, options?): BetaMessageBatch
POST/v1/messages/batches/{message_batch_id}/cancel

批次可在處理結束前隨時取消。一旦啟動取消,批次便會進入 canceling 狀態,此時系統可能會先完成任何進行中且不可中斷的請求,然後才完成取消。

刪除訊息批次
client.beta.messages.batches.delete(messageBatchID, params?, options?): BetaDeletedMessageBatch
DELETE/v1/messages/batches/{message_batch_id}

刪除訊息批次。

擷取訊息批次結果
client.beta.messages.batches.results(messageBatchID, params?, options?): BetaMessageBatchIndividualResponse | Stream<BetaMessageBatchIndividualResponse>
GET/v1/messages/batches/{message_batch_id}/results

以 .jsonl 檔案的形式串流傳輸訊息批次的結果。

Models
interface BetaDeletedMessageBatch { type: "message_batch_deleted"; id }
type: "message_batch_deleted"

Deleted object type.

For Message Batches, this is always "message_batch_deleted".

defaultmessage_batch_deleted
id: string

ID of the Message Batch.

interface BetaMessageBatch { type: "message_batch"; id; archived_at; /* 7 more */ }
interface BetaMessageBatchCanceledResult { type: "canceled" }
type: "canceled"
defaultcanceled
interface BetaMessageBatchErroredResult { type: "errored"; error }
type: "errored"
defaulterrored
error: BetaErrorResponse { type: "error"; error; request_id }
type: "error"
defaulterror
error: BetaError
One of the following:
request_id: string | null
interface BetaMessageBatchExpiredResult { type: "expired" }
type: "expired"
defaultexpired
interface BetaMessageBatchIndividualResponse { custom_id; result }

This is a single line in the response .jsonl file and does not represent the response as a whole.

custom_id: string

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.

One of the following:
interface BetaMessageBatchRequestCounts { canceled; errored; expired; /* 2 more */ }
canceled: number

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

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

default0
errored: number

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

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

default0
expired: number

Number of requests in the Message Batch that have expired.

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

default0
processing: number

Number of requests in the Message Batch that are processing.

default0
succeeded: number

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

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

default0

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.

One of the following:
interface BetaMessageBatchSucceededResult { type: "succeeded"; message }
type: "succeeded"
defaultsucceeded
message: BetaMessage { type: "message"; id; container; /* 10 more */ }