文件与批处理
获取 Message Batch 结果
以 JSONL 流的形式返回 Message Batch 的结果。
概述
以 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 -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"响应
{"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