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

  1. Give every input line a unique custom_id and persist a lookup from that ID to the source job.
  2. Read output and error files and join each item to the lookup by its custom_id.
  3. 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

Official guidance

OpenAI documentation