Claude Platform Docs

取消消息批次

messages.batches.cancel(message_batch_id, **kwargs) -> MessageBatch
POST/v1/messages/batches/{message_batch_id}/cancel

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

已取消请求的数量在 request_counts 中指定。要确定哪些请求已被取消,请检查批次中的各个结果。请注意,如果请求不可中断,取消操作可能不会导致任何请求被取消。

在我们的用户指南中了解有关 Message Batches API 的更多信息

Parameters
message_batch_id: String⁠Path parameter

ID of the Message Batch.

workspace_id: String⁠Header parameter

Optional header to select the Workspace for this request. The value is a Workspace ID (for example, wrkspc_011CZkZaBF1tNoB5wlCeusgy).

Only needed for credentials that can act on more than one Workspace. A credential that belongs to a specific Workspace may omit it; if sent, it must match that Workspace.

Returns
class MessageBatch { type: :message_batch, id, archived_at, 7 more }
取消消息批次
require "anthropic"

anthropic = Anthropic::Client.new(api_key: "my-anthropic-api-key")

message_batch = anthropic.messages.batches.cancel("message_batch_id")

puts(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"
}