Batches

View as Markdown

Batches

Submit a list of requests inline, kick off a batch, poll until done. Batch jobs run at discounted pricing. Results are returned inline in the poll response — no separate file download required.

1// 1. Create the batch
2const batch = await client.batches.create({
3 requests: [
4 {
5 custom_id: "req-1",
6 body: {
7 model: "openai/gpt-5.4",
8 messages: [{ role: "user", content: "Say hi." }],
9 },
10 },
11 {
12 custom_id: "req-2",
13 body: {
14 model: "openai/gpt-5.4",
15 messages: [{ role: "user", content: "Say bye." }],
16 },
17 },
18 ],
19 completion_window: "24h",
20});
21
22// 2. Poll later — results are included once status is "completed"
23const status = await client.batches.get(batch.id);
24if (status.status === "completed") {
25 for (const result of status.results ?? []) {
26 console.log(result.custom_id, result.response.body.choices[0].message.content);
27 }
28}