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

# Image Generation

> Synthesize high-resolution imagery from text prompts via /v1/images/generations.

The `/v1/images/generations` endpoint provides OpenAI Images API compatibility to generate images from natural language descriptions.

```python Python (OpenAI SDK) icon="python" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
from openai import OpenAI
import os

client = OpenAI(
    base_url="https://api.neosantara.xyz/v1",
    api_key=os.environ["NEOSANTARA_API_KEY"]
)

response = client.images.generate(
    model="imagen-4.0-fast",
    prompt="Terraced rice fields in Ubud Bali at sunrise, photorealistic, cinematic lighting.",
    size="1024x1024",
    n=1
)

image_url = response.data[0].url
print(f"Image URL: {image_url}")
```

```javascript Node.js (OpenAI SDK) icon="js" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.neosantara.xyz/v1",
  apiKey: process.env.NEOSANTARA_API_KEY,
});

const response = await client.images.generate({
  model: "imagen-4.0-fast",
  prompt: "Terraced rice fields in Ubud Bali at sunrise, photorealistic.",
  size: "1024x1024",
  n: 1,
});

console.log("Image URL:", response.data[0].url);
```

```bash cURL icon="terminal" theme={"theme":{"light":"catppuccin-latte","dark":"ayu-dark"}}
curl -X POST https://api.neosantara.xyz/v1/images/generations \
  -H "Authorization: Bearer $NEOSANTARA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "imagen-4.0-fast",
    "prompt": "Terraced rice fields in Ubud Bali at sunrise.",
    "size": "1024x1024",
    "n": 1
  }'
```

## Request Parameters

| Parameter | Type | Required | Description |
| :- | :- | :- | :- |
| `prompt` | `string` | Yes | Visual description of the desired image. |
| `model` | `string` | Yes | Model identifier (e.g., `imagen-4.0-fast`, `titan-image-g1`). |
| `size` | `string` | Optional | Output resolution (`1024x1024`, `512x512`). Default `1024x1024`. |
| `n` | `integer` | Optional | Number of image variations to generate (1 to 4). Default `1`. |
| `response_format` | `string` | Optional | Output format: `"url"` or `"b64_json"`. Default `"url"`. |

## Technical Architecture & Caching

* **Synchronous vs Asynchronous**: The standard `/v1/images/generations` endpoint operates synchronously for real-time applications. For high-resolution generation or batch pipelines, use the [Responses API](https://docs.neosantara.xyz/en/gateway/responses-api.md) with `background: true` to prevent HTTP timeouts.
* **Ephemeral CDN & TTL Caching**: Generated images are delivered through high-speed edge CDN storage via signed URLs. Links remain valid for **5 minutes** (TTL). Ingest assets into permanent cloud storage (S3/GCS/R2) if long-term persistence is required.
* **SSRF Mitigation**: When providing input image URLs for variations or inpainting, the gateway security bridge validates public IP ranges and blocks loopback or private addresses to prevent Server-Side Request Forgery.
* **Rupiah Metering**: Image generation is billed on a per-image unit basis rather than token count. Costs are deducted directly from your prepaid Rupiah balance.

## Visual Showcase

Output examples generated directly through the Neosantara API:

### Fast Inference

**Model**: `imagen-4.0-fast`

![Imagen 4.0 Fast output showcase](https://mintcdn.com/neosantara/uq2XlSQ_dSPDIOXL/images/showcase-imagen.png?fit=max\&auto=format\&n=uq2XlSQ_dSPDIOXL\&q=85\&s=43447f08eedeefd471665b5be062ef0c)

Prompt: 'A vibrant digital painting of a high-tech laboratory in Jakarta, neon highlights, futuristic design, extremely detailed.'

### Artistic & Fantasy

**Model**: `sdxl-lightning`

![Artistic fantasy output showcase](https://mintcdn.com/neosantara/uq2XlSQ_dSPDIOXL/images/showcase-artistic.png?fit=max\&auto=format\&n=uq2XlSQ_dSPDIOXL\&q=85\&s=af48e6100f66ad2de9e171b21fae5759)

Prompt: 'A majestic Indonesian temple in the clouds, ethereal lighting, high fantasy art style, 8k.'

### Realistic Photography

**Model**: `titan-image-g1`

![Realistic photography output showcase](https://mintcdn.com/neosantara/uq2XlSQ_dSPDIOXL/images/showcase-titan-base.png?fit=max\&auto=format\&n=uq2XlSQ_dSPDIOXL\&q=85\&s=c4bf3ea5d76fad12e98add5e77b5a68f)

Prompt: 'A realistic high-detail photograph of a Balinese traditional dancer performing at night, focused lighting.'

### Image-to-Image Transformation

**Model**: `stable-diffusion-v1-5-img2img`

Transform existing images into new visual styles while preserving original structural composition.

> [card] Original Image
>
> Input reference photograph of a Balinese dancer.

> [card] Sketch Transformation
>
> Stylized output transformed into a minimalist charcoal sketch.

## Available Image Generation Models

| Model ID | Provider | Context Window | Capabilities | Pricing (Input/Output per 1M) |
| :- | :- | :- | :- | :- |
| `agnes-image-2.0-flash` | Agnes AI | N/A | Image Gen | Free / Included |
| `agnes-image-2.1-flash` | Agnes AI | N/A | Image Gen | Free / Included |
| `agnes-image-2.5-flash` | Agnes AI | N/A | Image Gen | Free / Included |
| `imagen-4.0-fast` | Google | N/A | Image Gen | \$0.02/img |
| `neosantara-gen-2045` | Neosantara | N/A | Image Gen | Rp 1,500/img |
| `gpt-image-2` | OpenAI | N/A | Image Gen | \$0.04/img |
| `sdxl-lightning` | Stability AI | N/A | Image Gen | Rp 200/img |
| `stable-diffusion-v1-5-img2img` | Stability AI | N/A | Image Gen | Rp 200/img |
| `grok-imagine-image` | xAI | N/A | Image Gen | \$0.02/img |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.