Documentation · Batch searches
Batch image search
Send many queries in one job instead of looping over single searches.
Batch searches
Send several unique queries in one job, each with its own count. JSON bodies are limited to 64 KiB, so split very large batches across jobs. There’s no image-count cap, but source availability and your project’s daily limit still apply.
{
"queries": [
{
"query": "mountain landscape",
"count": "15"
},
{
"query": "wireless headphones",
"count": "30"
}
],
"min_width": 800,
"watermark_policy": "prefer_clean"
}Reading batch results
A batch is one job, so you read it with the same results endpoint as a single search. Every image carries the query it was found for, so you can group results by query as they arrive.
Each query also reports its own progress and stop reason in GET /v1/jobs/JOB_ID, so one query running out of images doesn’t hide the others. A batch finishes complete only when every query found what it asked for; otherwise it is partial.
const byQuery = {};
let after = 0;
while (true) {
const url = `${process.env.PLUKO_URL}/v1/jobs/${jobId}/results?limit=100&after=${after}`;
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.PLUKO_API_KEY}` },
});
const page = await response.json();
for (const image of page.images) (byQuery[image.query] ??= []).push(image);
if (page.next_cursor === null) break;
after = page.next_cursor;
}| Tip | Why |
|---|---|
| Keep queries unique | Duplicate queries in one batch are refused. |
| Stay under 64 KiB | Split very large lists into several jobs; each job is independent. |
| Set a count per query | Each item can carry its own count; a top-level count applies to items without one. |
| Use a webhook for big batches | Get one signed job.finished event instead of checking back. See Webhooks. |
Was this page helpful?
Tell us what’s missing. We read every note.