# Gemini Native Sync Image Generation

Generate images synchronously with `gemini-3.1-flash-image`, `gemini-3.0-pro-image`, or `nano-banana-2.1` via the native Gemini `generateContent` endpoint. Requests block until image generation completes; clients extract the image directly from the synchronous response following the [Client Extraction Order](#client-extraction-order) below—there is no async task ID and no polling.

> Model availability depends on the live response of `GET /v1/models` for your API key. Do not submit generation requests for models that do not appear in that list.

> None of the models on this page support OpenAI-compatible `/v1/chat/completions`. If you use an OpenAI-style client, `gemini-3.1-flash-image` and `gemini-3.0-pro-image` can be called via the async image endpoint described in [Calling via the Async Image Endpoint](#calling-via-the-async-image-endpoint) below.

## Endpoint & Authentication

```http
POST https://vip.brioi.com/v1beta/models/{model}:generateContent
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
```

Replace `{model}` with a model ID available to your API key. Authenticate with your Brioi API key via `Authorization: Bearer`, the `x-goog-api-key` header, or the `?key=` query parameter—the default `x-goog-api-key` header sent by official Gemini SDKs works directly.

List models visible to your API key:

```bash
curl "https://vip.brioi.com/v1/models" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Supported Models

| Model | Positioning | `imageSize` | `aspectRatio` |
|---|---|---|---|
| `gemini-3.1-flash-image` | Balanced speed and quality | `1K`, `2K`, `4K` (required) | `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `16:9`, `9:16`, `21:9` |
| `gemini-3.0-pro-image` | Quality-first | `1K`, `2K`, `4K` (required) | `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `16:9`, `9:16`, `21:9` |
| `nano-banana-2.1` | Balanced speed and quality | `1K`, `2K`, `4K` (optional; defaults to `1K` when omitted) | `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `16:9`, `9:16`, `21:9` |

`aspectRatio` can be omitted to let the model choose its default composition. Because `aspectRatio` expresses a composition preference, always read the actual pixel dimensions of the returned image. `nano-banana-2.1` only supports the `generateContent` endpoint on this page and does not support the async image endpoint.

## Request Schema

| Field | Type | Required | Description |
|---|---|---:|---|
| `contents` | array | Yes | Conversation turns; must include at least one non-empty item. |
| `contents[].role` | string | No | Recommended value for user prompts: `user`. |
| `contents[].parts` | array | Yes | Text instructions and reference image parts. |
| `parts[].text` | string | Conditional | Image generation or editing instructions. |
| `parts[].inlineData` | object | No | Base64 reference image containing `mimeType` and `data`. |
| `parts[].fileData` | object | No | Public URL reference image containing `mimeType` and `fileUri`. |
| `generationConfig.responseModalities` | string[] | Yes | Must include `IMAGE`. |
| `generationConfig.imageConfig.imageSize` | string | Yes | `1K`, `2K`, or `4K` (uppercase `K` required). Optional for `nano-banana-2.1` (defaults to `1K` when omitted). |
| `generationConfig.imageConfig.aspectRatio` | string | No | Aspect ratio supported by the target model. |

## Text-to-Image Example

```bash
curl -X POST "https://vip.brioi.com/v1beta/models/gemini-3.1-flash-image:generateContent" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [
        {"text": "A futuristic city skyline under a deep blue night sky, neon lights reflecting off rain-slicked streets, no text or watermarks"}
      ]
    }],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageConfig": {
        "imageSize": "4K",
        "aspectRatio": "9:16"
      }
    }
  }'
```

## URL Reference Image Example

`fileUri` must be a publicly accessible direct HTTPS image URL—not a web page, preview page, or URL requiring login or cookies. `mimeType` must match the actual MIME type of the remote file.

```bash
curl -X POST "https://vip.brioi.com/v1beta/models/gemini-3.1-flash-image:generateContent" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [
        {"text": "Add a five-pointed star to the image"},
        {
          "fileData": {
            "mimeType": "image/jpeg",
            "fileUri": "https://your-cdn.example/reference.jpg"
          }
        }
      ]
    }],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageConfig": {
        "imageSize": "1K",
        "aspectRatio": "1:1"
      }
    }
  }'
```

## Base64 Reference Image Example

Provide only the raw base64 payload in `inlineData.data`—do not include a `data:image/...;base64,` prefix.

```json
{
  "contents": [{
    "role": "user",
    "parts": [
      {"text": "Preserve the product structure and material, and replace the background with a clean white photo studio"},
      {
        "inlineData": {
          "mimeType": "image/png",
          "data": "BASE64_IMAGE_DATA"
        }
      }
    ]
  }],
  "generationConfig": {
    "responseModalities": ["IMAGE"],
    "imageConfig": {
      "imageSize": "2K",
      "aspectRatio": "1:1"
    }
  }
}
```

## Response & Image Extraction

In a successful response, `parts` may contain both text and images. Standard Gemini image output is located at `inlineData.data` and should be decoded according to `inlineData.mimeType`; remote image outputs follow the unified extraction order below.

```json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/jpeg",
              "data": "BASE64_IMAGE_DATA"
            }
          }
        ]
      },
      "finishReason": "STOP"
    }
  ]
}
```

In some cases, `inlineData` is omitted and the generated image is returned as a remote URL inside `candidate.content.parts[]` via one or both of the following forms:

1. `fileData.fileUri`
2. Markdown image syntax `![...](https://...)` inside `text`

The same image may appear simultaneously as both `fileData.fileUri` and a Markdown image URL. Clients must deduplicate URLs rather than treating them as two separate images.

### Remote Image Response Example

```json
{
  "candidates": [{
    "content": {
      "role": "model",
      "parts": [
        {
          "text": "![image](https://cdn.example/generated.png)"
        },
        {
          "fileData": {
            "mimeType": "image/png",
            "fileUri": "https://cdn.example/generated.png"
          }
        }
      ]
    },
    "finishReason": "STOP"
  }]
}
```

### Client Extraction Order

1. Decode `inlineData.data` first if present.
2. Otherwise, read `fileData.fileUri`.
3. Otherwise, extract Markdown image URLs from `parts[].text`.
4. Deduplicate URLs and verify that downloaded payloads are non-empty, decodable images.

> Standard Gemini SDKs typically recognize only `inlineData` as image output. When handling compatible remote image outputs, callers must implement the extraction and download logic above.

## Calling via the Async Image Endpoint

`gemini-3.0-pro-image` and `gemini-3.1-flash-image` can also be invoked through the async image endpoints, suitable for clients built around OpenAI-style REST conventions:

```http
POST https://vip.brioi.com/v1/images/async/generations
GET  https://vip.brioi.com/v1/images/async/generations/{task_id}
```

Request fields, reference image limits, aspect ratios, and size tiers match `nano-banana-pro` and `nano-banana-2`, respectively—see [Nano Banana Image Generation](https://docs.brioi.com/english/2552254m0.md): pass reference images via `image_urls`, set size tier and ratio via `image_size` (`1K`, `2K`, `4K`) and `aspect_ratio`, and set `n` to `1` only. Allowed `aspect_ratio` values follow the Nano Banana specification: on the async endpoint, `gemini-3.1-flash-image` supports only `1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `auto` (fewer than on this native endpoint), whereas `gemini-3.0-pro-image` supports `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9`, `auto`. Billing follows the `image_size` tier at the same pricing as the native endpoint; omitting `image_size` generates and bills at `1K`, and omitting `aspect_ratio` generates a `9:16` portrait image.

Neither model supports `/v1/chat/completions`, nor synchronous `/v1/images/generations` or `/v1/images/edits`—use the async image endpoint above or `generateContent` on this page.

## Limits & Error Handling

- `generationConfig.responseModalities` must include `IMAGE`.
- `imageSize` only accepts `1K`, `2K`, or `4K`; lowercase `k` is not part of the public API contract.
- `aspectRatio` must be an enum value supported by the target model (see [Supported Models](#supported-models)).
- URL reference images must be directly downloadable over the public internet and return the matching image MIME type; short-lived signed URLs must remain valid for the entire synchronous generation cycle.
- Base64 reference images must match their declared `mimeType`.
- Synchronous requests block until generation completes. If a client times out, do not blindly retry—capture the `X-Oneapi-Request-Id` response header and error details first to avoid duplicate generations.
- HTTP status codes: `400` invalid request parameters, `401` missing or invalid API key, `403` insufficient balance/quota or missing model permission, `429` rate limit exceeded, `503` service temporarily unavailable, `500` / `502` transient server error.

