AI Help
How do I match AI Batch API results to inputs when results arrive out of order?
Match Batch results to inputs by custom_id, since output order can differ from input order.
Steps to follow
- Give every input line a unique custom_id and persist a lookup from that ID to the source job.
- Read output and error files and join each item to the lookup by its custom_id.
- Check duplicate, unknown and missing IDs and reconcile the complete submitted set before marking the batch finished.
Example in practice
Illustrative example. If request-2 appears before request-1 in the output file, both still map to their correct source records.
Related AI help
- How do I retry only failed requests from an AI Batch API job?
- How do I avoid processing the same AI completion webhook twice?