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

# GPT-Image-2 · Text-to-image

> GPT-Image-2 Flare / Sunburst · POST /v1/images/generations

## Introduction

GPT-Image-2 turns text descriptions into illustrations, product visuals, posters, and infographics through POST /v1/images/generations. It supports flexible sizes and PNG, JPEG, and WebP output. Adjust quality, size, and background for your task. Transparent backgrounds are a preview capability for this model; confirm project and channel access.

## Authentication

**Authorization** `string` *required*

Bearer \$GRAVITEX\_API\_KEY

**Content-Type** `string` *required*

application/json

## Request parameters

| Parameter | Type | Description |
| - | - | - |
| `model` | string | Required: gpt-image-2 |
| `prompt` | string | Required description of the image to generate; up to 32,000 characters |
| `quality` | string | auto / low / medium / high; default auto |
| `size` | string | auto or WxH with dimensions divisible by 16; model size and pixel budgets apply |
| `n` | integer | 1–10 |
| `background` | string | auto / opaque / transparent; use png or webp for transparent raster output |
| `output_format` | string | png / jpeg / webp; default png |
| `output_compression` | integer | 0–100, default 100; JPEG / WebP only |
| `moderation` | string | auto / low; default auto |
| `safety_identifier` | string | Stable hashed end-user identifier, up to 128 characters; replaces user |
| `stream` | boolean | Default false. When true, read SSE events instead of parsing a single JSON response |
| `partial_images` | integer | Raster streaming only: 0–3, default 0. Requested preview count; fewer previews may arrive |

## Request examples

Examples read the platform token from GRAVITEX\_API\_KEY in your terminal environment. For uploads, curl -F generates Content-Type and boundary automatically; do not manually set a bare multipart/form-data header.

### Basic generation

```bash theme={null}
curl https://api.gravitex.ai/v1/images/generations \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2",
  "prompt": "A clean botanical poster with precise typography",
  "quality": "medium",
  "size": "1024x1024"
}'
```

### Transparent background

```bash theme={null}
curl https://api.gravitex.ai/v1/images/generations \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2",
  "prompt": "A single green botanical icon, isolated on a transparent background",
  "quality": "medium",
  "size": "1024x1024",
  "background": "transparent",
  "output_format": "png"
}'
```

user is deprecated and retained for compatibility. Use safety\_identifier; a non-empty value takes precedence, otherwise the API falls back to user.

### Streaming

```bash theme={null}
curl --no-buffer https://api.gravitex.ai/v1/images/generations \
  -H "Authorization: Bearer $GRAVITEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2",
  "prompt": "A simple green botanical illustration",
  "quality": "medium",
  "size": "1024x1024",
  "stream": true,
  "partial_images": 1
}'
```

## Limits and notes

The default size is auto. Explicit WxH dimensions must be multiples of 16, with aspect ratios between 1:3 and 3:1. The image-2 guide specifies a maximum edge of 3840px and 655,360–8,294,400 pixels.

quality supports auto / low / medium / high, default auto. Transparent backgrounds are in preview for image-2; when available, use background=transparent with PNG or WebP. This guide covers raster workflows and does not assume 2.6 complexity, GIF, SVG, or 2.5 markup support.

## Response example

This is a schematic non-streaming response. Image data and token counts are illustrative, not an actual generation. Decode b64\_json to the selected file format; do not save the Base64 text directly as an image.

```json theme={null}
{
  "created": 1794268800,
  "data": [
    {
      "b64_json": "<BASE64_IMAGE_DATA>"
    }
  ],
  "usage": {
    "input_tokens": 100,
    "output_tokens": 824,
    "total_tokens": 924
  }
}
```

With stream=true, read SSE events for previews and the final image. Do not parse the entire response as one JSON object.

## Response and billing

Non-streaming examples return image bytes as b64\_json. Do not request response\_format=url expecting a hosted image URL. Equal token rates do not imply equal cost per image; use actual usage.

Returns data\[].b64\_json and usage. Decode Base64 before saving images. The following are OpenAI standard rates, not a GravitexAI quote.

Cached rates are official reference rates. For GPT Image 2 / 2.5, the guide limits cached input discounts to the Responses image tool; they do not apply to direct Images API calls, including edits. Platform billing follows the console.

| Type | USD / 1M tokens |
| - | - |
| Text input | \$5.00 |
| Cached text input | \$1.25 |
| Image input | \$8.00 |
| Cached image input | \$2.00 |
| Image output | \$30.00 |

## Official references

* [Image generation guide](https://developers.openai.com/api/docs/guides/image-generation)
* [API Reference](https://developers.openai.com/api/reference/resources/images/methods/generate)
* [GPT-Image-2](https://developers.openai.com/api/docs/models/gpt-image-2)
* [Pricing](https://developers.openai.com/api/docs/pricing)


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