Berkas & batch

Mengambil Hasil Batch Pesan

Melakukan streaming hasil dari Message Batch sebagai JSONL.

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

Gambaran Umum

Lakukan streaming hasil dari Message Batch sebagai JSONL, satu baris per permintaan. Baca hasilnya setelah processing_status bernilai ended. Ini adalah URL yang sama dengan results_url di dalam objek batch.

Catatan

  • Setiap baris adalah {"custom_id": "...", "result": {...}}. Baris-baris tersebut tidak memiliki urutan tetap; cocokkan masing-masing berdasarkan custom_id.
  • result.type bisa berupa succeeded (dengan message, isi yang sama dengan respons Create Message), errored (dengan error), canceled, atau expired.
  • Di dalam message, model adalah ID model yang Anda kirimkan dalam permintaan.
  • Batch yang tidak ada atau telah dihapus akan mengembalikan 404. Batch yang belum siap untuk dibaca dapat mengembalikan 409; coba lagi nanti.

Contoh

Permintaan

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"

Contoh respons

Respons

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

Bidang penting

custom_idstring
custom_id yang Anda tetapkan pada permintaan.
result.typestring
succeeded, errored, canceled, atau expired.
result.messageobject
Pesan tersebut, saat result.type adalah succeeded.
result.errorobject
Kesalahan tersebut, saat result.type adalah errored.

Otorisasi

BearerAuth
AuthorizationBearer <token>

Autentikasi API Key. Buat atau kelola API key di Dashboard > API > API Keys.

Lokasi: header

Parameter path

message_batch_id*string

Pengidentifikasi batch pesan

Respons

application/x-ndjson

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json