---
title: "Image Generation"
method: POST
path: "/v1beta/models/gemini-2.5-flash-image:generateContent"
---

# Image Generation

`POST /v1beta/models/gemini-2.5-flash-image:generateContent`

Generate images using Gemini model.

## Query parameters

- `key` string, required

## Request body

- object
  - `contents` object[], required — Array of conversation turns. Each turn has a role and parts. A part can be a text prompt, or an inline_data image (base64). To use a reference image, include both a text part and an inline_data part in the same parts array.
    - `role` 'user' | 'model'
    - `parts` object[] — List of content parts. Combine text and inline_data in the same array to send a prompt alongside a reference image.
      - `text` string — Text prompt
      - `inline_data` object — Reference image encoded as base64. Replace `data` with your actual base64-encoded image string.
        - `mime_type` 'image/jpeg' | 'image/png' | 'image/webp' — MIME type of the image. Supported: image/jpeg, image/png, image/webp
        - `data` string — Base64-encoded image data. Paste your base64 string here. Example: convert your image with `base64 image.jpg` or use an online tool.
  - `generationConfig` object, required
    - `responseModalities` string[], required — Output modalities. Use ["IMAGE"] for image-only output, or ["TEXT", "IMAGE"] to receive both a caption and the image.
    - `imageConfig` object — Image generation configuration
      - `aspectRatio` '1:1' | '4:3' | '3:4' | '16:9' | '9:16' — Desired aspect ratio of the generated image.
      - `imageSize` '1K' | '2K' | '4K' — Resolution of the generated image. 1K ≈ 1024px, 2K ≈ 2048px, 4K ≈ 4096px on the long edge.

## Response `200`

Image generated successfully

- GenerateContentResponse
  - `candidates` object[]
    - `content` Content
      - `role` 'user' | 'model'
      - `parts` Part[], required
        - `text` string
        - `thought` boolean — Whether this part contains model reasoning.
        - `thoughtSignature` string — Opaque signature that must be preserved in multi-turn tool workflows.
        - `inlineData` object
          - `mimeType` string, required
          - `data` string, required — Base64-encoded image
        - `fileData` object
          - `mimeType` string, required
          - `fileUri` string, uri, required — Gemini Files URI or supported public media URL.
        - `functionCall` object
          - `name` string
          - `args` object
        - `functionResponse` object
          - `name` string
          - `id` string — Call ID returned by the model.
          - `response` object
        - `executableCode` object
          - `language` string
          - `code` string
        - `codeExecutionResult` object
          - `outcome` string
          - `output` string
    - `finishReason` string
    - `index` integer
    - `safetyRatings` object[], nullable
  - `usageMetadata` object
    - `promptTokenCount` integer
    - `candidatesTokenCount` integer
    - `cachedContentTokenCount` integer
    - `thoughtsTokenCount` integer
    - `toolUsePromptTokenCount` integer
    - `totalTokenCount` integer
    - `serviceTier` string
    - `promptTokensDetails` ModalityTokenCount[]
      - `modality` string
      - `tokenCount` integer
    - `toolUsePromptTokensDetails` ModalityTokenCount[], nullable
      - `modality` string
      - `tokenCount` integer
  - `modelVersion` string
  - `responseId` string
  - `quota` integer — AnyFast quota usage reported for the request.

## Other responses

- `400` — Invalid request
- `401` — Unauthorized
- `429` — Rate limit exceeded

---

[API](https://skmtc.net/anyfast/apis/anthropic-claude-compatible-endpoint.md) · [All operations](https://skmtc.net/anyfast/apis/anthropic-claude-compatible-endpoint/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/anyfast/anthropic-claude-compatible-endpoint/versions/edfc53e182a1/schema)
