SegmindSegmind / Docs

Batch API

Upload a JSONL or CSV file with up to 1,000 requests and get all results back in one file, at 50% off the standard price. Supported for Nano Banana and Nano Banana Pro.

The Batch API runs many requests for one model as a single job. You upload a file with one request per row, get a request_id back, and poll until the whole batch is done. The finished result is one JSONL or CSV file with a row per request. Every image generated in a batch costs 50% less than the same image through the standard API.

Use it for large jobs that don't need an answer right away, such as generating a product catalog or running a prompt list overnight. For single requests, use the async API instead.

Supported models: nano-banana and nano-banana-pro. Calling the batch endpoint with any other model returns 400 with the list of supported models.

Quick start

1. Prepare the input file

Each row is one request. JSONL example (requests.jsonl):

{"request_id": "shoe-red", "prompt": "a red running shoe on a white background, studio lighting"}
{"request_id": "shoe-blue", "prompt": "a blue running shoe on a white background, studio lighting"}
{"request_id": "shoe-edit", "prompt": "make the background a sunny beach", "image_urls": ["https://example.com/shoe.png"]}

The same requests as CSV (requests.csv):

request_id,prompt,image_urls
shoe-red,"a red running shoe on a white background, studio lighting",
shoe-blue,"a blue running shoe on a white background, studio lighting",
shoe-edit,make the background a sunny beach,https://example.com/shoe.png

2. Submit the batch

Send the file as multipart form data in a field named file:

curl -X POST "https://api.segmind.com/v1/nano-banana/batch" \
  -H "x-api-key: YOUR_API_KEY" \
  -F "file=@requests.jsonl"

Response:

{
  "request_id": "8f3c2a71-5d0e-4b9a-9c61-2e7f1a4b6d90",
  "status": "QUEUED",
  "total_requests": 3,
  "poll_url": "https://api.segmind.com/v1/batch/8f3c2a71-5d0e-4b9a-9c61-2e7f1a4b6d90",
  "message": "Batch queued for processing"
}

If some rows were skipped (see Validation), the response also has a warnings object:

"warnings": {
  "invalid_requests": 1,
  "message": "Skipped 1 invalid requests"
}

3. Poll for the result

curl "https://api.segmind.com/v1/batch/8f3c2a71-5d0e-4b9a-9c61-2e7f1a4b6d90" \
  -H "x-api-key: YOUR_API_KEY"

While the batch is running:

{
  "status": "PROCESSING",
  "output": ""
}

When it is done:

{
  "status": "COMPLETED",
  "output": "https://images.segmind.com/<user_id>/batches/8f3c2a71-5d0e-4b9a-9c61-2e7f1a4b6d90.jsonl",
  "successful_count": "3",
  "failed_count": "0",
  "total_requests": "3"
}

output is a URL to the result file, in the output format you chose. Download it to read the results. The counts are returned as strings. Poll every 30 to 60 seconds; see Turnaround for how long a batch can take.

The batch status is kept for 24 hours after you submit. The result file and the generated images stay available at their URLs after that. Anyone with a URL can open the file, so treat the URLs as private.

Endpoints

MethodPathPurpose
POST/v1/{model}/batchSubmit a batch file
GET/v1/batch/{request_id}Get batch status and result

Both endpoints take the usual x-api-key header.

Submit form fields

FieldRequiredDescription
fileYesA .jsonl or .csv file with at most 1,000 rows.
output_formatNojsonl or csv. Defaults to the format of the input file.

Request fields

FieldTypeRequiredModelsDescription
promptstringYesBothThe text prompt. Must not be empty.
request_idstringNoBothYour ID for this row. It is returned with the result. Generated for you if missing. Must be unique within the file.
image_urlsarray of URLs (JSONL), one URL (CSV)NoBothInput images for editing or reference. Must be public URLs.
aspect_ratiostringNonano-banana-proOutput aspect ratio, for example 1:1, 16:9, 9:16.
output_resolutionstringNonano-banana-proOutput size: 1K, 2K or 4K. Set it explicitly: unlike the standard API, batch does not default to 4K.

In CSV files, image_urls holds a single URL per row. To send more than one input image per request, use JSONL.

Validation

The batch is checked before it is queued:

  • Whole batch rejected (400): the file is missing, empty, not .jsonl or .csv, has more than 1,000 rows, contains invalid JSON, has a CSV without a header row, has duplicate request_id values, or has no valid rows at all.
  • Single row skipped: the row has no prompt, or one of its image_urls could not be downloaded. The other rows still run, and the count of skipped rows is shown in warnings. A skipped row does not appear in the result file and is not charged.

Output format

Each result row has these fields:

FieldDescription
request_idThe ID from your input row
statussuccess or failed
image_urlURL of the generated image (success only)
mime_typeimage/png or image/jpeg
finish_reasonWhy the model stopped, for example STOP
input_token_countInput tokens used by the row
output_token_countOutput tokens used by the row
error_codeError code (failed rows only)
error_messageError details (failed rows only)

In JSONL output, token counts are nested in a usage_metadata object. If the model answers with text instead of an image, the row has "response_type": "text" and the text in message.

Example JSONL rows:

{"request_id": "shoe-red", "status": "success", "response_type": "image", "image_url": "https://images.segmind.com/.../shoe-red.png", "mime_type": "image/png", "finish_reason": "STOP", "usage_metadata": {"input_token_count": 14, "output_token_count": 1290}}
{"request_id": "shoe-edit", "status": "failed", "error_code": "NO_IMAGE_DATA", "error_message": "No image or text found in response"}

Images are returned as PNG or JPEG; check mime_type on each row.

Batch statuses

StatusMeaning
QUEUEDAccepted and waiting to start
PROCESSINGRunning at the provider
COMPLETEDDone. output has the result file
FAILEDThe whole batch failed. See error_message

A COMPLETED batch can still contain failed rows. Check failed_count and the status of each row.

Turnaround

Batches run on Google's Gemini Batch API, which processes jobs when capacity is free instead of right away:

  • Target: Google aims to finish each batch within 24 hours. Most batches finish much sooner; small test batches typically complete in a few minutes. This target is not a guarantee.
  • Expiry: a batch that is still pending or running after 48 hours is expired by Google and returns no results.
  • No priority: batch jobs are not faster for being small. If you need a result in seconds, use the async API.
  • Not idempotent: submitting the same file twice runs and bills two batches. Store the request_id from the first submit and poll it instead of resubmitting.

Pricing and credits

Batch is billed per generated image at 50% of the standard price for that model and resolution:

ModelResolutionStandard priceBatch price
nano-bananaAll$0.040$0.020
nano-banana-pro1K / 2K$0.1523$0.0761
nano-banana-pro4K$0.2727$0.1364

The resolution is read from the size of each generated image. Only successful image rows are charged. Failed rows, skipped rows and text-only answers are free.

When you submit, an estimate is held from your balance. You need enough credits to cover it or the submit is rejected. When the batch finishes, you are charged for the images actually generated and the rest of the hold is released. If the whole batch fails, the hold is released in full.

On this page