Submit a list of requests inline, kick off a batch, poll until done. Batch jobs run at discounted pricing.
1 // 1. Create the batch 2 const batch = await client.batches.create({ 3 requests: [ 4 { 5 custom_id: "req-1", 6 body: { 7 model: "openai/gpt-4o-mini", 8 messages: [{ role: "user", content: "Say hi." }], 9 }, 10 }, 11 { 12 custom_id: "req-2", 13 body: { 14 model: "openai/gpt-4o-mini", 15 messages: [{ role: "user", content: "Say bye." }], 16 }, 17 }, 18 ], 19 completion_window: "24h", 20 }); 21 22 // 2. Poll later 23 const status = await client.batches.get(batch.id); 24 if (status.status === "completed" && status.output_file_id) { 25 // Returns raw JSONL content as Uint8Array 26 const outputBytes = await client.files.content(status.output_file_id); 27 }