TokenLab

Tệp và lô

Truy xuất kết quả lô tin nhắn

Truyền phát kết quả của một Lô tin nhắn (Message Batch) dưới dạng JSONL.

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

Tổng quan

Truyền phát kết quả của một Lô tin nhắn dưới dạng JSONL, mỗi dòng cho một yêu cầu. Hãy đọc kết quả sau khi processing_status là ended. Đây là cùng một URL với results_url trong đối tượng lô.

Lưu ý

  • Mỗi dòng có định dạng {"custom_id": "...", "result": {...}}. Các dòng không theo thứ tự cố định; hãy khớp từng dòng bằng custom_id.
  • result.type có thể là succeeded (kèm theo message, có cùng nội dung phản hồi như Tạo tin nhắn), errored (kèm theo error), canceled hoặc expired.
  • Trong message, model là ID mô hình mà bạn đã gửi trong yêu cầu.
  • Một lô không tồn tại hoặc đã bị xóa sẽ trả về 404. Một lô chưa sẵn sàng để đọc có thể trả về 409; hãy thử lại sau.

Ví dụ

Yêu cầu

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"

Ví dụ phản hồi

Phản hồi

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

Các trường quan trọng

custom_idstring
custom_id mà bạn đã thiết lập trong yêu cầu.
result.typestring
succeeded, errored, canceled hoặc expired.
result.messageobject
Tin nhắn, khi result.type là succeeded.
result.errorobject
Lỗi, khi result.type là errored.

Xác thực

BearerAuth
AuthorizationBearer <token>

Xác thực bằng Khóa API. Tạo hoặc quản lý khóa API trong Dashboard > API > API Keys.

Vị trí: header

Tham số đường dẫn

message_batch_id*string

Định danh batch tin nhắn

Phản hồi

application/x-ndjson

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json