---
title: AI Image Generation API | RunAPI
description: Generate, edit, upscale, and remove backgrounds with image models through one API.
url: https://runapi.ai/image.md
canonical: https://runapi.ai/image
locale: en
site: RunAPI
image: https://runapi.ai/assets/opengraph-f702f2b1.png
alternates:
  en: https://runapi.ai/image
  zh-CN: https://runapi.ai/zh-CN/image
  es: https://runapi.ai/es/image
  ja: https://runapi.ai/ja/image
  de: https://runapi.ai/de/image
  fr: https://runapi.ai/fr/image
  pt-BR: https://runapi.ai/pt-BR/image
  ko: https://runapi.ai/ko/image
  it: https://runapi.ai/it/image
  nl: https://runapi.ai/nl/image
  pl: https://runapi.ai/pl/image
  tr: https://runapi.ai/tr/image
  zh-TW: https://runapi.ai/zh-TW/image
  zh-HK: https://runapi.ai/zh-HK/image
  ar: https://runapi.ai/ar/image
  x-default: https://runapi.ai/image
---

> HTML version: https://runapi.ai/image
> Site index for agents: https://runapi.ai/llms.txt


Image API

# AI Image Generation API

Generate, edit, upscale, and remove backgrounds with Flux, Midjourney, Ideogram, GPT Image, and Imagen through one API.

- [Get API Key](https://runapi.ai/login)
- [Browse Models](https://runapi.ai/models.md)

57 image models - pay per image

- Image models: 57
- Below official: —
- Median latency: 16s

## Playground

- Flux Pro 1.1: ≈ $0.05 / image
- GPT Image 2: ≈ $0.02 / megapixel
- Midjourney v7: ≈ $0.08 / image

Prompt: Editorial product shot of a matte ceramic cup on brushed steel, single softbox, cold morning light

- Size: 1024 x 1024
- Style: photographic
- Batch: 4 images
- Mode: text_to_image

Est. cost: ≈ $0.05 / image

Examples

## Image gallery

### Portrait

![Portrait](https://cdn.runapi.ai/public/homepage/media-showcase/b331927cb3fcf76a-runapi.ai-flux-pro.jpg)


### Macaw

![Macaw](https://cdn.runapi.ai/public/homepage/media-showcase/b1ff27fb20bffd98-runapi.ai-midjourney-v7.jpg)




## Everything the image endpoint can do

- **Text to Image** - One prompt, one call. Size, style, and batch count are plain parameters on the same endpoint.
- **Image Editing** - Instruction-based edits on an existing image - change a material, a color, or a whole background.
- **Inpainting** - Mask a region and regenerate only that area, keeping the rest of the frame pixel-identical.


## Image models on one key

| Model | Provider | Price |
| --- | --- | --- |
| Flux/flux-2-klein | Black Forest Labs | $0.03 / image |
| Flux/flux-dev | Black Forest Labs | $0.06 / image |
| Flux/flux-pro | Black Forest Labs | $0.07 / image |
| Flux 2/flux-2-flex-remix-image | Black Forest Labs | $0.14-$0.24 / image |
| Flux 2/flux-2-flex-text-to-image | Black Forest Labs | $0.14-$0.24 / image |
| Flux 2/flux-2-max-remix-image | Black Forest Labs | $0.15 / image |
| Flux 2/flux-2-max-text-to-image | Black Forest Labs | $0.15 / image |
| Flux 2/flux-2-pro-remix-image | Black Forest Labs | $0.06-$0.07 / image |


[View all 57 image models](https://runapi.ai/models.md)


## Quickstart

### Generate an image

#### curl

```bash
curl https://runapi.ai/api/v1/flux/text_to_image \
  -H "Authorization: Bearer $RUNAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"flux-2-klein","prompt":"A cobalt vase on white marble."}'
```

#### Python

```python
import json
import os
import requests

response = requests.post(
    "https://runapi.ai/api/v1/flux/text_to_image",
    headers={"Authorization": f"Bearer {os.environ['RUNAPI_API_KEY']}"},
    json=json.loads("{\"model\":\"flux-2-klein\",\"prompt\":\"A cobalt vase on white marble.\"}")
)
response.raise_for_status()
print(response.json())
```

#### Node.js

```javascript
const response = await fetch("https://runapi.ai/api/v1/flux/text_to_image", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.RUNAPI_API_KEY,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({"model":"flux-2-klein","prompt":"A cobalt vase on white marble."})
});
console.log(await response.json());
```

#### Go

```go
package main

import (
    "io"
    "net/http"
    "os"
    "strings"
)

func main() {
    payload := strings.NewReader("{\"model\":\"flux-2-klein\",\"prompt\":\"A cobalt vase on white marble.\"}")
    request, err := http.NewRequest("POST", "https://runapi.ai/api/v1/flux/text_to_image", payload)
    if err != nil { panic(err) }
    request.Header.Set("Authorization", "Bearer "+os.Getenv("RUNAPI_API_KEY"))
    request.Header.Set("Content-Type", "application/json")
    response, err := http.DefaultClient.Do(request)
    if err != nil { panic(err) }
    defer response.Body.Close()
    io.Copy(os.Stdout, response.Body)
}
```

#### Response

```json
{
  "id": "tsk_example",
  "status": "processing"
}
```



## Four Steps to Your First Generation

**How it works**

1. **Get Your API Key** - One key for all 57 image models.
2. **Choose a Model** - Flux, Midjourney, GPT Image, Ideogram, Recraft — pick by style or speed.
3. **Send a Request** - POST to /api/v1/flux/text_to_image. We route to the best provider at the lowest price.
4. **Download Result** - Response includes a CDN URL. Images typically ready in 3-15 seconds.



## Why Developers Choose RunAPI

- **One Key, All Models** - Stop juggling API keys. One integration gives you access to 57 image models across all providers.
- **15-25% Cost Savings** - Our volume agreements with providers mean lower prices than going direct. No markup on top.
- **Automatic Failover** - If a provider goes down, we route to the next best option. Your app stays up.
- **OpenAI-Compatible** - Drop-in replacement for OpenAI SDK. Change one line of code to access any model.
- **Real-Time Billing** - Pay only for what you use. Per-request pricing with no minimums. Track costs per model, per project.
- **Data Privacy** - Our Privacy Policy explains how request data and generated content are processed and retained.



### Explore

## More AI APIs

- [Video API](https://runapi.ai/models.md?modality=video) - Generate, edit, and upscale video with 76 models [Learn more](https://runapi.ai/models.md?modality=video)
- [Music API](https://runapi.ai/models.md?modality=audio_music) - Compose original tracks with AI [Learn more](https://runapi.ai/models.md?modality=audio_music)
- [Audio API](https://runapi.ai/models.md?modality=audio_music) - Text-to-speech with 32 voices [Learn more](https://runapi.ai/models.md?modality=audio_music)
- [LLM API](https://runapi.ai/models.md?modality=text) - Chat completions with 66 language models [Learn more](https://runapi.ai/models.md?modality=text)



## What teams build with it

- **Product Catalogs** - Generate on-brand shots for thousands of SKUs, then cut backgrounds in the same pipeline.
- **Ad Creative** - Batch variants per channel and aspect ratio. Swap models without touching request code.
- **App Features** - Ship avatar, sticker, or thumbnail generation as a product feature with per-key spend caps.
- **Design Systems** - Keep a series consistent with image-to-prompt, then iterate with masked inpainting.



## RunAPI vs alternatives

| Feature | RunAPI | Direct API | Replicate |
| --- | --- | --- | --- |
| Image models | 57 | 1 provider | ~20 |
| Pricing | 15-25% below official | Official rate | Market rate + GPU markup |
| Response time | 3-15s typical | Varies | Cold start delays |
| Unified billing | ✓ | ✗ | ✓ |
| MCP server | ✓ | ✗ | ✗ |
| Provider failover | ✓ | ✗ | ✗ |


## Image API questions

### How is image generation billed?

Per image or per megapixel, depending on the model. The catalog lists the exact unit next to each price.

### Can I edit an image I already have?

Yes. Pass your image with task_type image_edit or inpaint, plus an instruction or a mask.

### Is Midjourney really available over API?

Yes, through RunAPI's managed integration. It uses the same request shape as every other image model.

### What is the maximum resolution?

Native resolution depends on the selected model; dedicated upscalers can produce 4K output where supported.

### Do you keep my images?

Output retention follows the active endpoint contract. RunAPI does not use prompts or outputs for training.

### Can I set a per-project spend limit?

Yes. Create a separate API key per project and set its available credit and reset cycle.

## Add image generation to your product

57 models behind one OpenAI-shaped request. Start free, no credit card required.

- [Get API Key](https://runapi.ai/login)
- [Read the Docs](https://runapi.ai/docs/guides)




---

## More from RunAPI

- [Home](https://runapi.ai/.md)
### Product
- [Model Catalog](https://runapi.ai/models.md)
- [Pricing](https://runapi.ai/pricing.md)
- [Providers](https://runapi.ai/models#all-models)
### Developers
- [Documentation](https://runapi.ai/docs/guides)
- [SDKs](https://runapi.ai/sdk.md)
- [CLI](https://runapi.ai/cli.md)
- [MCP Server](https://runapi.ai/mcp.md)
### Guides
- [Claude Code vs Cursor](https://runapi.ai/claude-code-vs-cursor.md)
- [Cursor API Setup](https://runapi.ai/cursor-api-setup.md)
- [RunAPI vs OpenRouter](https://runapi.ai/openrouter-alternative.md)
### Company
- [Enterprise](https://runapi.ai/contact.md)
- [Contact](https://runapi.ai/contact.md)
### Legal
- [Terms](https://runapi.ai/terms.md)
- [Privacy](https://runapi.ai/privacy.md)
- [Site index for agents](https://runapi.ai/llms.txt)

Contact: contact@runapi.ai

## Structured data

```json
[
  {
    "@context": "https://schema.org",
    "inLanguage": "en",
    "@type": "WebSite",
    "name": "RunAPI",
    "url": "https://runapi.ai/",
    "potentialAction": {
      "@type": "SearchAction",
      "target": {
        "@type": "EntryPoint",
        "urlTemplate": "https://runapi.ai/models?q={search_term_string}"
      },
      "query-input": "required name=search_term_string"
    }
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "en",
    "@type": "Organization",
    "name": "RunAPI",
    "url": "https://runapi.ai/",
    "logo": {
      "@type": "ImageObject",
      "url": "https://runapi.ai/icon.svg"
    },
    "sameAs": [
      "https://github.com/runapi-ai"
    ]
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "en",
    "@type": "SoftwareApplication",
    "name": "RunAPI",
    "applicationCategory": "DeveloperApplication",
    "description": "Generate, edit, upscale, and remove backgrounds with image models through one API.",
    "url": "https://runapi.ai/image"
  },
  {
    "@context": "https://schema.org",
    "inLanguage": "en",
    "@type": "BreadcrumbList",
    "itemListElement": [
      {
        "@type": "ListItem",
        "position": 1,
        "name": "Home",
        "item": "https://runapi.ai/"
      },
      {
        "@type": "ListItem",
        "position": 2,
        "name": "RunAPI",
        "item": "https://runapi.ai/image"
      }
    ]
  }
]
```
