文件与批处理

获取 Message Batch 结果

以 JSONL 流的形式返回 Message Batch 的结果。

GET
/v1/messages/batches/{message_batch_id}/results

概述

以 JSONL 流的形式返回 Message Batch 的结果,每个请求一行。请在 processing_status 变为 ended 之后读取结果。它与批次对象中的 results_url 是同一个 URL。

说明

  • 每一行形如 {"custom_id": "...", "result": {...}}。行的顺序不固定,请按 custom_id 对应每个请求。
  • result.type 为 succeeded(带 message,内容与创建消息的响应相同)、errored(带 error)、canceled 或 expired。
  • message 中的 model 是您在请求中发送的模型 ID。
  • 批次不存在或已删除时返回 404。批次尚未就绪时可能返回 409,请稍后重试。

示例

请求

cURL
curl -X GET "https://api.tokenlab.sh/v1/messages/batches/msgbatch_01ABC123/results" \
  -H "x-api-key: sk-your-api-key" \
  -H "anthropic-version: 2023-06-01"

响应示例

响应

200 OK (JSONL)
{"custom_id":"request-1","result":{"type":"succeeded","message":{"id":"msg_abc123","type":"message","role":"assistant","content":[{"type":"text","text":"Hello! How can I help you today?"}],"model":"claude-sonnet-5","stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":10,"output_tokens":9}}}}
{"custom_id":"request-2","result":{"type":"errored","error":{"type":"error","error":{"type":"invalid_request_error","message":"messages: at least one message is required"}}}}
{"custom_id":"request-3","result":{"type":"canceled"}}
{"custom_id":"request-4","result":{"type":"expired"}}

重要字段

custom_idstring
您在请求上设置的 custom_id。
result.typestring
succeeded、errored、canceled 或 expired。
result.messageobject
result.type 为 succeeded 时的消息。
result.errorobject
result.type 为 errored 时的错误。

授权

BearerAuth
AuthorizationBearer <token>

API Key 身份验证。在 Dashboard > API > API Keys 中创建或管理 API Key。

位置: header

路径参数

message_batch_id*string

消息批处理标识符

响应

application/x-ndjson

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json