# AI Image Generator API — Batch Text to Image, Pay per Image (`sherwood/image-generator-batch`) Actor

Generate images from one or many text prompts with FLUX (text to image) and get, for each image, a dataset item with the image URL, width, height and seed. Batch input, up to 4 variations per prompt, no API key, pay per image.

- **URL**: https://apify.com/sherwood/image-generator-batch.md
- **Developed by:** [Sherwood](https://apify.com/sherwood) (community)
- **Categories:** AI, Automation, Developer tools
- **Stats:** 3 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $20.00 / 1,000 image generateds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## AI Image Generator API — batch text to image (FLUX), pay per image

Give it one prompt or a thousand, get one image per prompt (or up to four variations) generated with FLUX.2 Klein 9B, one dataset item per image: the image URL, its width, height and seed, or a clear error. No API key, no GPU, no subscription. **$0.02 per image** delivered (1024×1024 included), failures are free.

Built for automation and AI agents: send a list in `prompts`, or one prompt (or a newline-separated string) in `prompt`; every alias (`prompts`, `prompt`, `texts`, `queries`) is merged, nothing is required, and the default input runs on its own so you can see the output shape before sending your own prompts.

Pairs with [Image Upscaler API](https://apify.com/sherwood/image-upscaler-batch) (enlarge the result to print size) and [Background Remover API](https://apify.com/sherwood/background-remover-batch) (cut the subject out).

### What you get

One item per generated image, in your dataset:

```json
{
  "index": 0,
  "variant": 0,
  "prompt": "A ceramic coffee mug on a wooden table, soft morning light, product photography",
  "outputUrl": "https://api.apify.com/v2/key-value-stores/abc123/records/image-0000-0.png",
  "width": 1024,
  "height": 1024,
  "seed": 674885436,
  "model": "fal-ai/flux-2/klein/9b",
  "format": "png",
  "durationMs": 6200,
  "status": "ok",
  "error": null
}
```

A prompt that fails, or an image flagged by the safety checker, comes back with `"status": "error"` and the reason in `error`. It is never charged. Pass the `seed` back with the same prompt to reproduce an image.

### Use cases

- Generate product mock-ups, hero images and illustrations for landing pages in bulk.
- Produce one image per article, post or ad variant from a content calendar.
- Create thumbnails and social visuals straight from an n8n / Make / Zapier flow.
- Give an AI agent a single call that turns a list of ideas into a list of images.

### Input

| Field | Type | Default | Notes |
|---|---|---|---|
| `prompts` | array | two sample prompts | English works best. For one prompt or a newline-separated string, use `prompt`. |
| `prompt`, `texts`, `queries` | aliases | — | Merged with `prompts`. |
| `imageSize` | preset | `square_hd` | `square_hd` 1024×1024, `landscape_4_3` 1024×768, `landscape_16_9` 1024×576, `portrait_4_3`, `portrait_16_9`, `square` 512×512. |
| `width`, `height` | integer | — | Exact pixels (256 to 2048), override `imageSize` when both are given. |
| `quality` | `standard`, `fast` | `standard` | standard = FLUX.2 Klein 9B; fast = FLUX Schnell, about twice as fast, for drafts. |
| `imagesPerPrompt` | 1 to 4 | `1` | Variations per prompt; each image is charged. |
| `outputFormat` | `png`, `jpeg`, `webp` | `png` | |
| `seed` | integer | random | Fix it to reproduce an image. |
| `maxPrompts` | integer | `100` | Stop after this many prompts. |

Minimal call:

```json
{ "prompts": ["A red bicycle leaning on a brick wall, golden hour", "Isometric icon of a cloud server, flat design"] }
```

### Pricing

- **Image generated** — $0.02 per image delivered, output up to 1024×1024 included.
- **Extra megapixel** — $0.01 per started megapixel above 1.1 MP for custom sizes (2048×2048 is 4.2 MP, so 3 extra).
- Failed prompts and safety-flagged images: free.

Set a maximum cost per run in Apify and the Actor stops cleanly when it is reached; remaining prompts are reported, not processed.

### Via API, n8n, Make or MCP

Call it like any Apify Actor: `POST https://api.apify.com/v2/actors/sherwood~image-generator-batch/run-sync-get-dataset-items` with the JSON input above, or add it as a tool through the Apify MCP server. Results are plain dataset items, so `get-dataset-items` returns the URLs directly.

### Limits

- Generation time is typically 4 to 10 seconds per image; 4 prompts are processed in parallel.
- A safety checker is always on: prompts producing unsafe content return an error item instead of an image.
- Output files live in the run's key-value store and follow your account's data retention.

# Actor input Schema

## `prompts` (type: `array`):

Text descriptions of the images to generate, as a list, in English for best results. One dataset item is returned per generated image, with an index matching the prompt order. For a single prompt, or several prompts in one newline-separated string, use prompt instead. Aliases merged into this list: prompt, texts, queries.

## `prompt` (type: `string`):

A single prompt, or several prompts in one newline-separated string (one prompt per line). Merged with prompts.

## `texts` (type: `array`):

Alias of prompts.

## `queries` (type: `array`):

Alias of prompts.

## `imageSize` (type: `string`):

Aspect ratio preset. square_hd is 1024×1024, landscape_4_3 is 1024×768, landscape_16_9 is 1024×576, portrait presets are the same sizes rotated, square is 512×512. For exact pixels use width and height instead.

## `width` (type: `integer`):

Exact output width in pixels, 256 to 2048. Overrides imageSize when both width and height are given. Output is charged per started megapixel above 1 MP.

## `height` (type: `integer`):

Exact output height in pixels, 256 to 2048. Overrides imageSize when both width and height are given.

## `quality` (type: `string`):

standard uses FLUX.2 Klein 9B (sharper detail, better text rendering). fast uses FLUX Schnell (about twice as fast, cheaper, good for drafts and thumbnails).

## `imagesPerPrompt` (type: `integer`):

Generate 1 to 4 variations per prompt. Each image is charged.

## `outputFormat` (type: `string`):

File format of the generated image.

## `seed` (type: `integer`):

Fix the seed to make a prompt reproducible. Leave empty for a random image each run.

## `maxPrompts` (type: `integer`):

Stop after this many prompts. Protects against oversized lists. Default 100.

## Actor input object example

```json
{
  "prompts": [
    "A ceramic coffee mug on a wooden table, soft morning light, product photography, plain white background",
    "Minimal flat illustration of a paper plane flying over mountains, pastel colors"
  ],
  "imageSize": "square_hd",
  "quality": "standard",
  "imagesPerPrompt": 1,
  "outputFormat": "png",
  "maxPrompts": 100
}
```

# Actor output Schema

## `results` (type: `string`):

One item per generated image: prompt, outputUrl, width, height, seed, status and error. Sort by index to match the prompt order.

## `files` (type: `string`):

The generated image files referenced by outputUrl.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "prompts": [
        "A ceramic coffee mug on a wooden table, soft morning light, product photography, plain white background",
        "Minimal flat illustration of a paper plane flying over mountains, pastel colors"
    ],
    "imageSize": "square_hd",
    "quality": "standard",
    "imagesPerPrompt": 1,
    "outputFormat": "png",
    "maxPrompts": 100
};

// Run the Actor and wait for it to finish
const run = await client.actor("sherwood/image-generator-batch").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "prompts": [
        "A ceramic coffee mug on a wooden table, soft morning light, product photography, plain white background",
        "Minimal flat illustration of a paper plane flying over mountains, pastel colors",
    ],
    "imageSize": "square_hd",
    "quality": "standard",
    "imagesPerPrompt": 1,
    "outputFormat": "png",
    "maxPrompts": 100,
}

# Run the Actor and wait for it to finish
run = client.actor("sherwood/image-generator-batch").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "prompts": [
    "A ceramic coffee mug on a wooden table, soft morning light, product photography, plain white background",
    "Minimal flat illustration of a paper plane flying over mountains, pastel colors"
  ],
  "imageSize": "square_hd",
  "quality": "standard",
  "imagesPerPrompt": 1,
  "outputFormat": "png",
  "maxPrompts": 100
}' |
apify call sherwood/image-generator-batch --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,sherwood/image-generator-batch"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/5CZcBFudCzelodURl/builds/sQ9rU7aJhpoczRA2w/openapi.json
