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

# Gemini Format - Image Generation

> - Uses the Gemini native format generateContent endpoint to generate images
- Enable image output by setting `generationConfig.responseModalities` to `["TEXT", "IMAGE"]` or `["IMAGE"]`
- Supports text-to-image: generate images from text prompts
- Supports image-to-image: upload an image + text prompt for image editing
- Supports multi-turn conversation for iterative image modifications
- Control aspect ratio and image resolution via `generationConfig.imageConfig`
- For streaming, use `/v1beta/models/{model}:streamGenerateContent?alt=sse`




## OpenAPI

````yaml openapi/en/gemini-format-image-generation.json POST /v1beta/models/{model}:generateContent
openapi: 3.1.0
info:
  title: Gemini Format - Image Generation
  version: '1.0'
servers:
  - url: https://api.aihubmax.com
security:
  - BearerAuth: []
paths:
  /v1beta/models/{model}:generateContent:
    post:
      tags:
        - Text Series > Gemini Format
      summary: Gemini Format - Image Generation
      description: >
        - Uses the Gemini native format generateContent endpoint to generate
        images

        - Enable image output by setting `generationConfig.responseModalities`
        to `["TEXT", "IMAGE"]` or `["IMAGE"]`

        - Supports text-to-image: generate images from text prompts

        - Supports image-to-image: upload an image + text prompt for image
        editing

        - Supports multi-turn conversation for iterative image modifications

        - Control aspect ratio and image resolution via
        `generationConfig.imageConfig`

        - For streaming, use
        `/v1beta/models/{model}:streamGenerateContent?alt=sse`
      operationId: gemini-format-image-generation
      parameters:
        - name: model
          in: path
          required: true
          schema:
            type: string
            example: gemini-3.1-flash-image-preview
            enum:
              - gemini-3-pro-image-preview
              - gemini-3.1-flash-image-preview
          description: >-
            Model name. Supports `gemini-3-pro-image-preview` (professional
            asset creation, advanced reasoning) and
            `gemini-3.1-flash-image-preview` (high efficiency, optimized for
            speed)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageGenerationRequest'
            examples:
              text-to-image:
                summary: Text-to-image (basic)
                description: >-
                  Generate an image from a text prompt, returns text + image by
                  default
                value:
                  contents:
                    - role: user
                      parts:
                        - text: >-
                            Generate a watercolor painting of a lighthouse by
                            the sea at sunset
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
              image-only:
                summary: Text-to-image (image only)
                description: Set responseModalities to ["IMAGE"] to return only the image
                value:
                  contents:
                    - role: user
                      parts:
                        - text: >-
                            A corgi wearing a spacesuit walking on the moon,
                            cartoon style
                  generationConfig:
                    responseModalities:
                      - IMAGE
              with-aspect-ratio:
                summary: Custom aspect ratio and resolution
                description: Set aspect ratio and output resolution via imageConfig
                value:
                  contents:
                    - role: user
                      parts:
                        - text: Design a modern minimalist coffee shop menu poster
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
                    imageConfig:
                      aspectRatio: '9:16'
                      imageSize: 2K
              image-editing:
                summary: Image editing (image-to-image)
                description: >-
                  Upload an image + text instructions to edit and modify the
                  image
                value:
                  contents:
                    - role: user
                      parts:
                        - text: >-
                            Change the sky in this photo to a starry night
                            effect
                        - inlineData:
                            mimeType: image/jpeg
                            data: BASE64_ENCODED_IMAGE_DATA
                  generationConfig:
                    responseModalities:
                      - TEXT
                      - IMAGE
      responses:
        '200':
          $ref: '#/components/responses/ImageGenerationSuccess'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    ImageGenerationRequest:
      type: object
      required:
        - contents
        - generationConfig
      properties:
        contents:
          type: array
          description: List of conversation contents
          items:
            type: object
            required:
              - role
              - parts
            properties:
              role:
                type: string
                description: Role of the message sender
                enum:
                  - user
                  - model
              parts:
                type: array
                description: List of content parts, can include text and images
                items:
                  type: object
                  properties:
                    text:
                      type: string
                      description: >-
                        Text content (image generation prompt or editing
                        instructions)
                    inlineData:
                      type: object
                      description: >-
                        Inline data (for image editing scenarios, upload the
                        image to be edited)
                      required:
                        - mimeType
                        - data
                      properties:
                        mimeType:
                          type: string
                          description: MIME type
                          enum:
                            - image/png
                            - image/jpeg
                            - image/webp
                        data:
                          type: string
                          description: Base64 encoded image data
                    fileData:
                      type: object
                      description: >-
                        URL reference. Provide a reference image via a public
                        HTTPS URL (avoids base64 encoding overhead).
                      required:
                        - fileUri
                      properties:
                        fileUri:
                          type: string
                          description: Public HTTPS URL of the image
                          examples:
                            - https://example.com/photo.jpg
                        mimeType:
                          type: string
                          description: Image MIME type
                          enum:
                            - image/png
                            - image/jpeg
                            - image/webp
                  description: >-
                    Content part: text (text prompt) / inlineData (base64 image)
                    / fileData (image URL).


                    For image generation scenarios, input only supports text and
                    image types.
        systemInstruction:
          type: object
          description: System instruction
          properties:
            parts:
              type: array
              description: System instruction content parts
              items:
                type: object
                properties:
                  text:
                    type: string
                    description: System instruction text
        generationConfig:
          type: object
          description: >-
            Generation config (responseModalities must be set for image
            generation)
          required:
            - responseModalities
          properties:
            responseModalities:
              type: array
              description: >-
                Response modalities. Set to `["TEXT", "IMAGE"]` to return text +
                image (default), or `["IMAGE"]` to return image only
              items:
                type: string
                enum:
                  - TEXT
                  - IMAGE
              example:
                - TEXT
                - IMAGE
            temperature:
              type: number
              description: Sampling temperature
              minimum: 0
              maximum: 2
            imageConfig:
              type: object
              description: Image output configuration
              properties:
                aspectRatio:
                  type: string
                  description: Output image aspect ratio. Default is 1:1
                  enum:
                    - '1:1'
                    - '1:4'
                    - '1:8'
                    - '2:3'
                    - '3:2'
                    - '3:4'
                    - '4:1'
                    - '4:3'
                    - '4:5'
                    - '5:4'
                    - '8:1'
                    - '9:16'
                    - '16:9'
                    - '21:9'
                  example: '16:9'
                imageSize:
                  type: string
                  description: >-
                    Output image resolution. Default is 1K. Must use uppercase K
                    (e.g. 1K, 2K, 4K); 512 has no K suffix
                  enum:
                    - '512'
                    - 1K
                    - 2K
                    - 4K
                  example: 1K
        safetySettings:
          type: array
          description: Safety settings
          items:
            type: object
            properties:
              category:
                type: string
                description: Safety category
                enum:
                  - HARM_CATEGORY_HARASSMENT
                  - HARM_CATEGORY_HATE_SPEECH
                  - HARM_CATEGORY_SEXUALLY_EXPLICIT
                  - HARM_CATEGORY_DANGEROUS_CONTENT
              threshold:
                type: string
                description: Safety threshold
                enum:
                  - BLOCK_NONE
                  - BLOCK_LOW_AND_ABOVE
                  - BLOCK_MEDIUM_AND_ABOVE
                  - BLOCK_ONLY_HIGH
    ImageGenerationResponse:
      type: object
      properties:
        candidates:
          type: array
          description: List of candidate results
          items:
            type: object
            properties:
              content:
                type: object
                description: Generated content
                properties:
                  parts:
                    type: array
                    description: List of content parts, may contain both text and images
                    items:
                      type: object
                      properties:
                        text:
                          type: string
                          description: >-
                            Generated text content (when responseModalities
                            includes TEXT)
                          example: >-
                            Here is a watercolor painting of a lighthouse by the
                            sea at sunset.
                        inlineData:
                          type: object
                          description: Generated image data
                          properties:
                            mimeType:
                              type: string
                              description: Image MIME type
                              example: image/png
                            data:
                              type: string
                              description: Base64 encoded image data
                              example: iVBORw0KGgoAAAANSUhEUgAA...
                  role:
                    type: string
                    description: Role
                    enum:
                      - model
              finishReason:
                type: string
                description: Reason for generation stop
                enum:
                  - STOP
                  - MAX_TOKENS
                  - SAFETY
                  - RECITATION
                  - OTHER
                example: STOP
              safetyRatings:
                type: array
                description: Safety ratings list
                items:
                  type: object
                  properties:
                    category:
                      type: string
                      description: Safety category
                    probability:
                      type: string
                      description: Probability level
        usageMetadata:
          type: object
          description: Usage statistics
          properties:
            promptTokenCount:
              type: integer
              description: Prompt token count
              example: 15
            candidatesTokenCount:
              type: integer
              description: Candidates token count (includes image tokens)
              example: 1120
            totalTokenCount:
              type: integer
              description: Total token count
              example: 1135
    ErrorResponse400:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Invalid request parameters
            type:
              type: string
              example: invalid_request_error
    ErrorResponse401:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Invalid API Key
            type:
              type: string
              example: authentication_error
    ErrorResponse403:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Access denied
            type:
              type: string
              example: permission_error
    ErrorResponse429:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Rate limit exceeded
            type:
              type: string
              example: rate_limit_error
    ErrorResponse500:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Internal server error
            type:
              type: string
              example: server_error
  responses:
    ImageGenerationSuccess:
      description: Image generation response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ImageGenerationResponse'
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse401'
    PaymentRequired:
      description: Insufficient balance
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse403'
    TooManyRequests:
      description: Too many requests
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse429'
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse500'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |
        ## All endpoints require Bearer Token authentication ##

        Add the following to your request headers:

        `Authorization: Bearer YOUR_API_KEY`

````