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

# AI Image Generation API

> Generate images with FLUX, Stable Diffusion, and Ideogram via a single API. Text-to-image, image editing, and batch generation.

export const RuncrateStyles = () => {
  if (typeof document !== 'undefined' && !document.getElementById('runcrate-overrides')) {
    const s = document.createElement('style');
    s.id = 'runcrate-overrides';
    s.textContent = `
      /* Match Runcrate's rounding scale (--radius: 0.75rem) */
      .rounded-sm { border-radius: 0.5rem !important; }   /* 8px */
      .rounded-md { border-radius: 0.625rem !important; } /* 10px */
      .rounded-lg { border-radius: 0.75rem !important; }  /* 12px */
      .rounded-l-sm { border-top-left-radius: 0.5rem !important; border-bottom-left-radius: 0.5rem !important; }
      .rounded-r-sm { border-top-right-radius: 0.5rem !important; border-bottom-right-radius: 0.5rem !important; }
      .rounded-l-md { border-top-left-radius: 0.625rem !important; border-bottom-left-radius: 0.625rem !important; }
      .rounded-r-md { border-top-right-radius: 0.625rem !important; border-bottom-right-radius: 0.625rem !important; }
      .rounded-l-lg { border-top-left-radius: 0.75rem !important; border-bottom-left-radius: 0.75rem !important; }
      .rounded-r-lg { border-top-right-radius: 0.75rem !important; border-bottom-right-radius: 0.75rem !important; }

      /* Cards: never pure white in light mode */
      .card { background-color: #fcfcfc !important; border-radius: 0.75rem !important; }
      html.dark .card { background-color: #141414 !important; }

      /* Docs hero box */
      .rc-hero { background-color: #fcfcfc; border: 1px solid #e0e0e0; }
      html.dark .rc-hero { background-color: #141414; border-color: #242424; }
      html.dark .rc-hero h1 { color: #f5f5f5; }

      /* Runcrate scrollbar — thin, transparent track, hide-until-hover thumb */
      ::-webkit-scrollbar { width: 6px; height: 6px; background-color: transparent; }
      ::-webkit-scrollbar-track { background-color: transparent; }
      ::-webkit-scrollbar-thumb { background-color: rgba(155, 155, 155, 0.5); border-radius: 10px; transition: opacity 0.3s ease; opacity: 0; }
      ::-webkit-scrollbar-thumb:hover { background-color: rgba(155, 155, 155, 0.7); }
      *:hover::-webkit-scrollbar-thumb,
      *:focus::-webkit-scrollbar-thumb,
      *:active::-webkit-scrollbar-thumb { opacity: 1; }
      * { scrollbar-width: thin; scrollbar-color: rgba(155, 155, 155, 0.5) transparent; }
    `;
    document.head.appendChild(s);
  }
  return null;
};

<RuncrateStyles />

Generate images from text prompts using FLUX.1, FLUX.2, Stable Diffusion, and Ideogram through a single API. One API key, one endpoint, eight model families — no GPU management.

## Available models

| Model                    | Speed  | Quality   | Features                             |
| ------------------------ | ------ | --------- | ------------------------------------ |
| **FLUX.1 Schnell**       | Fast   | Good      | Text-to-image, best for prototyping  |
| **FLUX.1 Dev**           | Medium | High      | Open weights, img2img support        |
| **FLUX.1 Pro**           | Medium | Very High | Production-grade                     |
| **FLUX.1.1 Pro**         | Medium | Very High | Updated Pro model                    |
| **FLUX.2 Pro**           | Medium | Highest   | Up to 4MP, multi-reference images    |
| **FLUX Kontext**         | Medium | High      | Image editing with text instructions |
| **Stable Diffusion 3.5** | Medium | High      | Open weights                         |
| **Ideogram v2**          | Medium | High      | Best text rendering in images        |

***

## Basic text-to-image

<CodeGroup>
  ```bash curl theme={"theme":"github-dark"}
  curl https://api.runcrate.ai/v1/images/generations \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer rc_live_YOUR_API_KEY" \
    -d '{
      "model": "black-forest-labs/FLUX.1-schnell",
      "prompt": "A minimalist product photo of wireless earbuds on a marble surface, soft studio lighting, white background",
      "aspect_ratio": "1:1"
    }'
  ```

  ```python Python (OpenAI SDK) theme={"theme":"github-dark"}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.runcrate.ai/v1",
      api_key="rc_live_YOUR_API_KEY",
  )

  response = client.images.generate(
      model="black-forest-labs/FLUX.1-schnell",
      prompt="A minimalist product photo of wireless earbuds on a marble surface, soft studio lighting, white background",
  )

  print(response.data[0].url)
  ```

  ```python Python (Runcrate SDK) theme={"theme":"github-dark"}
  from runcrate import Runcrate

  client = Runcrate(api_key="rc_live_YOUR_API_KEY")

  image = client.models.generate_image(
      model="black-forest-labs/FLUX.1-schnell",
      prompt="A minimalist product photo of wireless earbuds on a marble surface, soft studio lighting, white background",
  )

  # Save directly to disk
  image.data[0].save("earbuds.png")
  ```

  ```typescript TypeScript (Runcrate SDK) theme={"theme":"github-dark"}
  import Runcrate from '@runcrate/sdk';

  const rc = new Runcrate({ apiKey: 'rc_live_YOUR_API_KEY' });

  const image = await rc.models.generateImage({
    model: 'black-forest-labs/FLUX.1-schnell',
    prompt: 'A minimalist product photo of wireless earbuds on a marble surface, soft studio lighting, white background',
  });

  // Save directly — handles base64, data URIs, and URLs
  await image.save('earbuds.png');
  ```

  ```typescript Vercel AI SDK theme={"theme":"github-dark"}
  import { runcrate } from '@runcrate/ai';
  import { generateImage } from 'ai';

  const { image } = await generateImage({
    model: runcrate.imageModel('black-forest-labs/FLUX.1-schnell'),
    prompt: 'A minimalist product photo of wireless earbuds on a marble surface, soft studio lighting, white background',
    size: '1024x1024',
  });

  console.log(image.base64);
  ```
</CodeGroup>

***

## Image editing with FLUX Kontext

FLUX Kontext models accept an existing image and a text instruction describing the edit. Pass a file path, URL, or base64 string as the `image` parameter.

<CodeGroup>
  ```python Python theme={"theme":"github-dark"}
  from runcrate import Runcrate

  client = Runcrate(api_key="rc_live_YOUR_API_KEY")

  # Edit an existing image with a text instruction
  edited = client.models.generate_image(
      model="black-forest-labs/FLUX.1-kontext-pro",
      prompt="Change the background to a tropical beach at sunset",
      image="./product-photo.png",  # file path (auto base64-encoded)
  )

  edited.data[0].save("product-beach.png")
  ```

  ```typescript TypeScript theme={"theme":"github-dark"}
  import Runcrate from '@runcrate/sdk';

  const rc = new Runcrate({ apiKey: 'rc_live_YOUR_API_KEY' });

  const edited = await rc.models.generateImage({
    model: 'black-forest-labs/FLUX.1-kontext-pro',
    prompt: 'Change the background to a tropical beach at sunset',
    image: './product-photo.png',  // file path (auto base64-encoded)
  });

  await edited.save('product-beach.png');
  ```
</CodeGroup>

<Tip>
  The `image` field accepts three formats:

  * **File path** — `"./photo.png"` (auto-detected, read and base64-encoded)
  * **URL** — `"https://..."` (passed through as-is)
  * **Base64 string** — raw base64 data (passed through as-is)
</Tip>

***

## Batch generation — product catalog

Generate a full set of product images in one script. This example creates hero images for an e-commerce catalog:

```python theme={"theme":"github-dark"}
from runcrate import Runcrate

client = Runcrate(api_key="rc_live_YOUR_API_KEY")

products = [
    {"name": "Running Shoe", "prompt": "A sleek running shoe, white background, studio lighting"},
    {"name": "Backpack", "prompt": "A modern laptop backpack, minimalist, product photography"},
    {"name": "Watch", "prompt": "A luxury watch on marble surface, soft shadows"},
]

for product in products:
    image = client.models.generate_image(
        model="black-forest-labs/FLUX.1-schnell",
        prompt=product["prompt"],
    )
    filename = f"{product['name'].lower().replace(' ', '-')}.png"
    image.data[0].save(filename)
    print(f"Saved {filename}")
```

For higher throughput, run generations in parallel:

```python theme={"theme":"github-dark"}
from runcrate import Runcrate
from concurrent.futures import ThreadPoolExecutor

client = Runcrate(api_key="rc_live_YOUR_API_KEY")

products = [
    {"name": "Running Shoe", "prompt": "A sleek running shoe, white background, studio lighting"},
    {"name": "Backpack", "prompt": "A modern laptop backpack, minimalist, product photography"},
    {"name": "Watch", "prompt": "A luxury watch on marble surface, soft shadows"},
    {"name": "Sunglasses", "prompt": "Designer sunglasses on a reflective surface, dramatic lighting"},
    {"name": "Headphones", "prompt": "Over-ear headphones floating, dark background, rim lighting"},
]

def generate(product):
    image = client.models.generate_image(
        model="black-forest-labs/FLUX.1-schnell",
        prompt=product["prompt"],
    )
    filename = f"{product['name'].lower().replace(' ', '-')}.png"
    image.data[0].save(filename)
    print(f"Saved {filename}")

with ThreadPoolExecutor(max_workers=5) as pool:
    pool.map(generate, products)

print("All product images generated.")
```

***

## Parameters reference

Parameters vary by model. These are the most common:

| Parameter             | Type    | Description                                                  |
| --------------------- | ------- | ------------------------------------------------------------ |
| `model`               | string  | Model ID (required)                                          |
| `prompt`              | string  | Text description of the image (required)                     |
| `aspect_ratio`        | string  | Output ratio: `1:1`, `16:9`, `9:16`, `4:3`, `3:2`            |
| `seed`                | integer | Reproducibility seed (omit for random)                       |
| `num_inference_steps` | integer | Number of diffusion steps — more steps = more detail, slower |
| `guidance`            | number  | How closely to follow the prompt                             |
| `negative_prompt`     | string  | What to avoid in the image                                   |

### Model-specific parameters

* **FLUX Kontext models**: Accept `image` for image editing
* **FLUX Canny**: Requires `control_image` for edge-guided generation
* **FLUX.2 Pro**: Accepts up to 8 `input_images` for reference-based generation
* **FLUX Dev/Krea**: Accept `image` for img2img mode with `prompt_strength` control

Check the [Playground](/models/playground) to see the exact parameters available for each model.

***

## Next.js API route

Add image generation to a web app with a single API route:

```typescript theme={"theme":"github-dark"}
// app/api/generate-image/route.ts
import { runcrate } from '@runcrate/ai';
import { generateImage } from 'ai';

export async function POST(req: Request) {
  const { prompt, model, aspectRatio } = await req.json();

  const { image } = await generateImage({
    model: runcrate.imageModel(model || 'black-forest-labs/FLUX.1-schnell'),
    prompt,
    size: aspectRatio === '16:9' ? '1792x1024' : '1024x1024',
  });

  return Response.json({ image: image.base64 });
}
```

Call it from the frontend:

```typescript theme={"theme":"github-dark"}
const response = await fetch('/api/generate-image', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    prompt: 'A mountain landscape at golden hour',
    model: 'black-forest-labs/FLUX.1-schnell',
    aspectRatio: '16:9',
  }),
});

const { image } = await response.json();
// image is a base64 string — render it in an <img> tag
```

***

## Response format

All image generation requests return the same shape:

```json theme={"theme":"github-dark"}
{
  "data": [
    {
      "url": "https://...",
      "b64_json": "..."
    }
  ]
}
```

The response includes either a `url` to the generated image or `b64_json` base64-encoded image data. The Runcrate SDKs provide a `.save()` helper that handles both formats automatically.

***

## Pricing

Image generation pricing varies by model. FLUX.1 Schnell starts at \~\$0.003/image. Higher-quality models like FLUX.2 Pro cost more per generation. Check the [Model Catalog](/models/model-catalog) for current per-model pricing.
