> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Generate images

> Generate or edit images with platform or provider credentials.

`generateImage` creates images from text or edits source images with an optional mask. Omit `account` to use the platform Vercel AI Gateway credential. Platform generations run in the background, and the result signal emits after generation finishes. Their model cost counts toward the organization's monthly [Platform AI allowance](/concepts/platform-resources#platform-ai); customer-managed accounts don't use this allowance. The platform default is `bfl/flux-2-flex` and generates at most 16 images per action. Use a provider account for larger batches.

If background generation exhausts its retries, the result signal fails with the provider error and prevents dependent actions from running.

## Generate an image

```ts automations/create-campaign-image.automation.ts theme={null}
import {
  automation,
  generateImage,
  markSignificant,
  onDashboardRun,
  withPrerequisites,
} from "automate.ax"

export default automation("Create campaign image", () => {
  const run = onDashboardRun({ title: "Create campaign image" })

  const result = withPrerequisites(run, () =>
    generateImage({
      aspectRatio: "16:9",
      prompt:
        "A paper-cut illustration of a solar-powered city at sunrise, no text",
    }),
  )

  markSignificant(result.images[0]!)
})
```

An organization member starts generation from the dashboard. The first image appears in the action output, and `markSignificant` keeps the completed run in the default Recent runs view. Each run uses the organization's Platform AI allowance.

## Edit images

Pass source images and an optional mask in the structured prompt. Each image or mask can be a `Blob`, base64 string, data URL, HTTP(S) URL, `Uint8Array`, or `ArrayBuffer`. `generateImage` normalizes these inputs, but the selected provider and model must support image editing and masks.

`sourceImageBytes` and `maskBytes` can be byte signals returned by earlier actions. Mark the edited image so the completed run stays visible:

```ts theme={null}
const edited = generateImage({
  prompt: {
    images: [sourceImageBytes],
    mask: maskBytes,
    text: "Replace the masked background with a snowy mountain range",
  },
})

markSignificant(edited.images[0]!)
```

## Inputs

| Input              | Type                                                                     | Required | Description                                                                                                                               |
| ------------------ | ------------------------------------------------------------------------ | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `prompt`           | `string \| { images: DataContent[]; text?: string; mask?: DataContent }` | Yes      | Text-to-image prompt or image editing/variation input.                                                                                    |
| `model`            | `GenerateImageModelId`                                                   | No       | Gateway or provider-native image model ID. Available models and the default depend on `account`.                                          |
| `account`          | Provider account reference                                               | No       | Customer-managed provider credentials. Omit for the platform gateway.                                                                     |
| `n`                | `number`                                                                 | No       | Number of images to generate. Defaults to `1`. Platform AI accepts at most `16`. Provider accounts aren't subject to that platform limit. |
| `size`             | `` `${number}x${number}` ``                                              | No       | Requested pixel dimensions, such as `1024x1024`. Use this or `aspectRatio` according to the model.                                        |
| `aspectRatio`      | `` `${number}:${number}` ``                                              | No       | Requested aspect ratio, such as `16:9`. Use this or `size` according to the model.                                                        |
| `seed`             | `number`                                                                 | No       | Provider-supported deterministic seed.                                                                                                    |
| `maxImagesPerCall` | `number`                                                                 | No       | Maximum images in each provider call. `generateImage` combines split calls into one result.                                               |
| `maxRetries`       | `number`                                                                 | No       | Maximum retries for each provider call. Defaults to `2`.                                                                                  |
| `providerOptions`  | `Record<string, Record<string, JSONValue>>`                              | No       | Provider-specific image options such as quality, background, output format, or moderation.                                                |
| `headers`          | `Record<string, string>`                                                 | No       | Additional request headers for HTTP-based providers.                                                                                      |

Generation inputs accept compatible signals. Account selection is static. Model autocomplete follows the selected provider, but arbitrary string IDs remain valid for newly released models.

The inputs mirror the AI SDK `generateImage` surface. `generateImage` also accepts `Blob` source images and normalizes generated files to `Blob` values. It omits `abortSignal` because actions execute durably after planning, so an in-memory `AbortSignal` can't control the later provider call.

## Output

`images` contains every generated image as a `Blob`. The first generated image is `images[0]`. Read its media type from `blob.type`, and use standard Blob methods such as `arrayBuffer()`, `bytes()`, or `text()` when you need the contents.

`generateImage` also returns provider `warnings`, combined token `usage` when reported, `providerMetadata`, and a `responses` entry for each underlying provider call. Each response includes its start timestamp, model ID, and optional headers.

## Provider accounts

Connect credentials with `bunx automate.ax accounts`, then pass a named account reference. API keys don't appear in automation code or signals.

| Account                       | Default model                                  |
| ----------------------------- | ---------------------------------------------- |
| Platform or Vercel AI Gateway | `bfl/flux-2-flex`                              |
| DeepInfra                     | `black-forest-labs/FLUX-1-schnell`             |
| Fireworks AI                  | `accounts/fireworks/models/flux-1-schnell-fp8` |
| Google Generative AI          | `imagen-4.0-fast-generate-001`                 |
| OpenAI                        | `gpt-image-1-mini`                             |
| Together AI                   | `black-forest-labs/FLUX.1-schnell-Free`        |
| xAI                           | `grok-imagine-image`                           |

Pass a named provider account and mark the generated file:

```ts theme={null}
import { generateImage, markSignificant } from "automate.ax"
import { openaiAccount } from "automate.ax/openai"

const productShot = generateImage({
  account: openaiAccount("creative"),
  model: "gpt-image-2",
  prompt: "A studio product photo of a cobalt blue travel mug",
  providerOptions: {
    openai: {
      background: "transparent",
      quality: "high",
    },
  },
})

markSignificant(productShot.images[0]!)
```

This uses the connected OpenAI account instead of the Platform AI allowance. The provider can charge that account for each generation.
