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

# Gemini Image

> Generate chat completions using Gemini ILM model with image inputs.

<Info>
  **Product**: Visual Intelligence — Image Model APIs (atomic)
  **Use case**: Call an Image Language Model (Gemini / GPT / Nova / Qwen) directly with your own prompt. Full control over model and parameters.
  **Host**: `https://mavi-backend.memories.ai/serve/api/v2`
  **Auth**: `Authorization: sk-mavi-...` (no `Bearer` prefix)
</Info>

This endpoint allows you to generate chat completions with image inputs using Gemini ILM model.

<Info>
  **Endpoint:** `POST https://mavi-backend.memories.ai/serve/api/v2/iu/chat/completions`

  Image Understanding (ILM) endpoints use the `/iu` path prefix. Video Understanding (VLM) endpoints use `/vu` instead.
</Info>

## Supported Models

All models require the `gemini:` prefix when used in the `model` parameter (e.g., `gemini:gemini-2.5-flash`).

### Premium Models

| Model                    | Input Price                         | Output Price                     |
| ------------------------ | ----------------------------------- | -------------------------------- |
| **gemini-3-pro-preview** | \$2/1M (≤200K), \$4/1M (>200K)      | \$12/1M (≤200K), \$18/1M (>200K) |
| **gemini-2.5-pro**       | \$1.25/1M (≤200K), \$2.5/1M (>200K) | \$10/1M (≤200K), \$15/1M (>200K) |

### Flash Models (High Performance)

| Model                                | Input Price      | Output Price    |
| ------------------------------------ | ---------------- | --------------- |
| **gemini-3-flash-preview**           | \$0.5/1M tokens  | \$3/1M tokens   |
| **gemini-2.5-flash**                 | \$0.30/1M tokens | \$2.5/1M tokens |
| **gemini-2.5-flash-preview-09-2025** | \$0.30/1M tokens | \$2.5/1M tokens |
| **gemini-2.0-flash**                 | \$0.1/1M tokens  | \$0.4/1M tokens |

### Lite Models (Cost-Effective)

| Model                                     | Input Price       | Output Price    |
| ----------------------------------------- | ----------------- | --------------- |
| **gemini-2.5-flash-lite**                 | \$0.1/1M tokens   | \$0.4/1M tokens |
| **gemini-2.5-flash-lite-preview-09-2025** | \$0.1/1M tokens   | \$0.4/1M tokens |
| **gemini-2.0-flash-lite**                 | \$0.075/1M tokens | \$0.3/1M tokens |

<Note>
  When using these models, remember to include the `gemini:` prefix in your API calls:

  * ✅ Correct: `"model": "gemini:gemini-2.5-flash"`
  * ❌ Incorrect: `"model": "gemini-2.5-flash"`
</Note>

### Request Body

| Parameter          | Type                    | Required | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------ | ----------------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| model              | string                  | Yes      | -       | The model to use (e.g., `gemini:gemini-2.5-flash`)                                                                                                                                                                                                                                                                                                                                                                                                                       |
| messages           | array                   | Yes      | -       | Array of message objects. Each message contains:<br />- `role`: Role type, values: `system`, `user`, `assistant`<br />- `content`: Message content, can be a string or array. Array items can contain:<br />  - `type`: Content type, `text` or `input_file`<br />  - `text`: Text content (when type is text)<br />  - `file_uri`: File URL or base64 encoded file (when type is input\_file)<br />  - `mime_type`: MIME type of the file (e.g., image/jpeg, video/mp4) |
| temperature        | number                  | No       | 0.7     | Controls randomness: 0.0-2.0, higher = more random                                                                                                                                                                                                                                                                                                                                                                                                                       |
| max\_tokens        | integer                 | No       | 1000    | Maximum number of tokens to generate                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| top\_p             | number                  | No       | 1.0     | Nucleus sampling: 0.0-1.0, consider tokens with top\_p probability mass                                                                                                                                                                                                                                                                                                                                                                                                  |
| frequency\_penalty | number                  | No       | 0.0     | Reduces repetition of frequent tokens: -2.0 to 2.0                                                                                                                                                                                                                                                                                                                                                                                                                       |
| presence\_penalty  | number                  | No       | 0.0     | Increases likelihood of new topics: -2.0 to 2.0                                                                                                                                                                                                                                                                                                                                                                                                                          |
| n                  | integer                 | No       | 1       | Number of completions to generate                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| stream             | boolean                 | No       | false   | Whether to stream the response                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| stop               | string \| array \| null | No       | null    | Stop sequences. Can be a string, array of strings, or null                                                                                                                                                                                                                                                                                                                                                                                                               |
| extra\_body        | object                  | No       | -       | Additional body parameters. Contains:<br />- `metadata`: Metadata object<br />  - `thinking_config`: Thinking configuration<br />    - `thinking_budget`: Integer value for thinking budget<br />  - `response_mime_type`: Response MIME type (`application/json` or `json_schema`)<br />  - `responseSchema`: JSON schema object for structured output                                                                                                                  |

### Code Example

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(
      api_key="sk-mavi-...",
      base_url="https://mavi-backend.memories.ai/serve/api/v2/iu"
  )

  def call_my_ilm():
      resp = client.chat.completions.create(
          model="gemini:gemini-2.5-flash",  # e.g. gemini:gemini-3-flash-preview or gemini:gemini-2.5-flash
          messages=[
              {"role": "system", "content": "You are a multimodal assistant. Keep your answers concise."},
              {
                  "role": "user",
                  "content": [
                      {
                          "type": "text",
                          "text": "Please summarize the content of this image"
                      },
                      {
                          "type": "input_file",
                          "file_uri": "https://storage.googleapis.com/memories-test-data/gun5.png",  # base64 or url
                          "mime_type": "image/jpeg"
                      }
                  ]
              }
          ],
          temperature=0.7,  # Controls randomness: 0.0-2.0, higher = more random
          max_tokens=1000,  # Maximum number of tokens to generate
          top_p=1.0,  # Nucleus sampling: 0.0-1.0, consider tokens with top_p probability mass
          frequency_penalty=0.0,  # -2.0 to 2.0, reduces repetition of frequent tokens
          presence_penalty=0.0,  # -2.0 to 2.0, increases likelihood of new topics
          n=1,  # Number of completions to generate
          stream=False,  # Whether to stream the response
          stop=None,  # Stop sequences (list of strings)
          extra_body={
              "metadata": {
                  "thinking_config": {
                      "thinking_budget": 1024
                  },
                  "response_mime_type": "application/json",  # application/json, json_schema
                  "responseSchema": {
                      "type": "OBJECT",
                      "properties": {
                          "image_summary": {
                              "type": "STRING",
                              "description": "Summary of the image content."
                          }
                      },
                      "required": [
                          "image_summary"
                      ]
                  }
              }
          }
      )
      return resp

  # Usage example
  result = call_my_ilm()
  print(result)
  ```
</CodeGroup>

### Response

Returns the chat completion response with structured output.

<ResponseExample>
  ```json theme={null}
  {
    "id": "resp_f8d13263-95b3-4337-b4c9-dbe9f6eb1e43",
    "object": "completion",
    "model": "gemini:gemini-2.5-flash",
    "created_at": 1767093024,
    "status": "completed",
    "choices": [
      {
        "text": "This image shows a humorous scene presented from a first-person perspective (FPS).\n\n**Main Scene:**\n*   In the center of the frame, both hands are holding weapons",
        "index": 0
      }
    ],
    "usage": {
      "input_tokens": 1812,
      "output_tokens": 38,
      "total_tokens": 1850
    },
    "meta": {
      "provider": "gemini",
      "provider_model": "gemini-2.5-flash"
    }
  }
  ```
</ResponseExample>

### Response Parameters

| Parameter            | Type    | Description                                       |
| -------------------- | ------- | ------------------------------------------------- |
| id                   | string  | Unique identifier for the completion              |
| object               | string  | Object type, always "completion"                  |
| model                | string  | The model used for the completion                 |
| created\_at          | integer | Unix timestamp of when the completion was created |
| status               | string  | Status of the completion (e.g., "completed")      |
| choices              | array   | Array of completion choices                       |
| choices\[].text      | string  | Text content of the completion                    |
| choices\[].index     | integer | Index of the choice in the choices array          |
| usage                | object  | Token usage information                           |
| usage.input\_tokens  | integer | Number of input tokens used                       |
| usage.output\_tokens | integer | Number of output tokens generated                 |
| usage.total\_tokens  | integer | Total number of tokens used                       |
| meta                 | object  | Metadata about the completion                     |
| meta.provider        | string  | Provider name (e.g., "gemini")                    |
| meta.provider\_model | string  | Provider-specific model name                      |

### Error Responses

<Warning>
  **Gemini upstream errors are wrapped in `HTTP 200`** — not a 4xx/5xx. Same envelope as [gemini-vlm](/visual-intelligence/gemini/gemini-vlm#error-responses): check `status` and look for a top-level `error` object before parsing `choices`.

  ```json theme={null}
  {
    "id": "resp_...",
    "object": "completion",
    "status": "errored",
    "choices": [],
    "usage": {"input_tokens": 0, "output_tokens": 0, "total_tokens": 0},
    "error": {
      "code": "INVALID_ARGUMENT",
      "message": "Unable to submit request because Model input cannot be empty. ...",
      "http_status": 400
    },
    "meta": {
      "provider": "gemini",
      "provider_http_status": 400,
      "provider_error": { "error": { "code": 400, "message": "...", "status": "INVALID_ARGUMENT" } }
    }
  }
  ```

  Verified live by submitting an empty input. This envelope is **Gemini-specific** — GPT, Nova, and Qwen use standard HTTP 4xx/5xx instead. Always check `status == "completed"` (or that `choices` is non-empty) before reading `choices[0].text`.
</Warning>


## OpenAPI

````yaml visual-intelligence/gemini/openapi.json POST /iu/chat/completions
openapi: 3.1.0
info:
  title: Gemini API Reference
  description: REST APIs for Gemini ILM and VLM models
  version: v1.0.0
servers:
  - url: https://mavi-backend.memories.ai/serve/api/v2
security:
  - ApiKeyAuth: []
paths:
  /iu/chat/completions:
    post:
      summary: Chat Completions Gemini ILM
      description: >-
        Generate chat completions using Gemini ILM or VLM models with image and
        video inputs.
      operationId: chat_completions_gemini_ilm
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                model:
                  type: string
                  description: The model to use (e.g., gemini:gemini-2.5-flash)
                  example: gemini:gemini-2.5-flash
                messages:
                  type: array
                  description: Array of message objects
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        enum:
                          - system
                          - user
                          - assistant
                      content:
                        oneOf:
                          - type: string
                          - type: array
                            items:
                              type: object
                              properties:
                                type:
                                  type: string
                                  enum:
                                    - text
                                    - input_file
                                text:
                                  type: string
                                file_uri:
                                  type: string
                                  description: URL or base64 encoded file
                                mime_type:
                                  type: string
                                  description: >-
                                    MIME type of the file (e.g., image/jpeg,
                                    video/mp4)
                    required:
                      - role
                      - content
                temperature:
                  type: number
                  description: 'Controls randomness: 0.0-2.0, higher = more random'
                  minimum: 0
                  maximum: 2
                  default: 0.7
                max_tokens:
                  type: integer
                  description: Maximum number of tokens to generate
                  default: 1000
                top_p:
                  type: number
                  description: 'Nucleus sampling: 0.0-1.0'
                  minimum: 0
                  maximum: 1
                  default: 1
                frequency_penalty:
                  type: number
                  description: 'Reduces repetition of frequent tokens: -2.0 to 2.0'
                  minimum: -2
                  maximum: 2
                  default: 0
                presence_penalty:
                  type: number
                  description: 'Increases likelihood of new topics: -2.0 to 2.0'
                  minimum: -2
                  maximum: 2
                  default: 0
                'n':
                  type: integer
                  description: Number of completions to generate
                  default: 1
                stream:
                  type: boolean
                  description: Whether to stream the response
                  default: false
                stop:
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        type: string
                    - type: 'null'
                  description: Stop sequences
                extra_body:
                  type: object
                  properties:
                    metadata:
                      type: object
                      properties:
                        thinking_config:
                          type: object
                          properties:
                            thinking_budget:
                              type: integer
                        response_mime_type:
                          type: string
                          enum:
                            - application/json
                            - json_schema
                        responseSchema:
                          type: object
                          properties:
                            type:
                              type: string
                              enum:
                                - OBJECT
                            properties:
                              type: object
                            required:
                              type: array
                              items:
                                type: string
              required:
                - model
                - messages
      responses:
        '200':
          description: Chat completion response
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: resp_f8d13263-95b3-4337-b4c9-dbe9f6eb1e43
                    description: Unique identifier for the completion
                  object:
                    type: string
                    example: completion
                    description: Object type, always 'completion'
                  model:
                    type: string
                    example: gemini:gemini-2.5-flash
                    description: The model used for the completion
                  created_at:
                    type: integer
                    example: 1767093024
                    description: Unix timestamp of when the completion was created
                  status:
                    type: string
                    example: completed
                    description: Status of the completion
                  choices:
                    type: array
                    items:
                      type: object
                      properties:
                        text:
                          type: string
                          description: Text content of the completion
                          example: >-
                            This image shows a humorous scene presented from a
                            first-person perspective (FPS).
                        index:
                          type: integer
                          description: Index of the choice in the choices array
                          example: 0
                      required:
                        - text
                        - index
                  usage:
                    type: object
                    properties:
                      input_tokens:
                        type: integer
                        description: Number of input tokens used
                        example: 1812
                      output_tokens:
                        type: integer
                        description: Number of output tokens generated
                        example: 38
                      total_tokens:
                        type: integer
                        description: Total number of tokens used
                        example: 1850
                    required:
                      - input_tokens
                      - output_tokens
                      - total_tokens
                  meta:
                    type: object
                    properties:
                      provider:
                        type: string
                        description: Provider name
                        example: gemini
                      provider_model:
                        type: string
                        description: Provider-specific model name
                        example: gemini-2.5-flash
                    required:
                      - provider
                      - provider_model
                required:
                  - id
                  - object
                  - model
                  - created_at
                  - status
                  - choices
                  - usage
                  - meta
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization

````