- Symptom
- Answers are attached to the wrong input rowsThe result for the second request arrives before the first
- Cause
- Batch results can be returned in any order, not in submission order, so pairing results with inputs by position mislabels them.
- Fix
- Give every request a unique custom_id (1 to 64 letters, digits, hyphens, or underscores) and join results on it. Handle each result type: succeeded, errored, canceled, expired.
- Apply
const byId = new Map(inputs.map(i => [i.custom_id, i])); for await (const r of await client.messages.batches.results(batchId)) { const input = byId.get(r.custom_id); if (r.result.type !== 'succeeded') { console.warn(r.custom_id, r.result.type); continue; } }- Affected
- Message Batches API, all models, as of 2026-10
- Sources
Last verified 2026-10-15 · Confirmed by 0 builders