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

# Vertex Image generation

***

## Request

<CodeGroup>
  ```shellscript cURL theme={null}
  curl --location "https://api.znapai.com/v1beta1/projects/default/locations/global/publishers/google/models/gemini-3.1-flash-image-preview:generateContent" \
    --header "Authorization: Bearer $ZnapAI_API_KEY" \
    --header "Content-Type: application/json" \
    --header 'spend-logs-metadata: {"user_id": "user-123", "project_id": "proj_abc", "env": "production"}' \
    --data '{
      "contents": [
        {
          "role": "user",
          "parts": [
            {
              "text": "Generate an image of an F35 flying"
            }
          ]
        }
      ],
      "generationConfig": {
        "candidateCount": 1
      }
    }'
  ```
</CodeGroup>

## Response

```json theme={null}
{
    "candidates": [
        {
            "content": {
                "role": "model",
                "parts": [
                    {
                        "inlineData": {
                            "mimeType": "image/png",
                            "data": "iVBORwZP...ggQGt+y0AAAAASUVORK5CYII="
                        }
                    }
                ]
            },
            "finishReason": "STOP"
        }
    ],
    "usageMetadata": {
        "promptTokenCount": 6,
        "candidatesTokenCount": 1290,
        "totalTokenCount": 1296,
        "trafficType": "ON_DEMAND",
        "promptTokensDetails": [
            {
                "modality": "TEXT",
                "tokenCount": 6
            }
        ],
        "candidatesTokensDetails": [
            {
                "modality": "IMAGE",
                "tokenCount": 1290
            }
        ]
    },
    "modelVersion": "gemini-3.1-flash-image-preview",
    "createTime": "2026-04-08T17:31:32.596160Z",
    "responseId": "9JDWacCxJNiipt8Psd7RoQs"
}
```

## Image from base64 data

<Frame>
  <img src="https://mintcdn.com/znapai/e_hNWUukYYh3LnHU/images/vertex_image.png?fit=max&auto=format&n=e_hNWUukYYh3LnHU&q=85&s=7db6da063eebb7104b11d48100f59d85" alt="Vertex Image" width="1024" height="1024" data-path="images/vertex_image.png" />
</Frame>

***

## Parameters

<ParamField path="spend-logs-metadata" type="header" required={false}>
  An optional header used for spend logging metadata, containing JSON properties like `user_id`, `project_id`, and `env`.
</ParamField>

<ParamField path="contents" type="array" required>
  The conversation history or input prompts as an array of content objects.

  <Expandable title="contents[]" defaultOpen="True">
    <ResponseField name="role" type="string">
      The role of the creator of the content (e.g. `"user"` or `"model"`).
    </ResponseField>

    <ResponseField name="parts" type="array" required>
      An ordered list of parts that constitute a single message turn.

      <Expandable title="parts[]" defaultOpen="True">
        <ResponseField name="text" type="string">
          The text prompt or description for image generation.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField path="systemInstruction" type="object">
  Instructions to the model that dictate how it should behave.

  <Expandable title="systemInstruction" defaultOpen="True">
    <ResponseField name="parts" type="array" required>
      An ordered list of parts that constitute the system instruction.

      <Expandable title="parts[]" defaultOpen="True">
        <ResponseField name="text" type="string">
          The text of the system instruction.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField path="generationConfig" type="object">
  Configuration options for the generation.

  <Expandable title="generationConfig" defaultOpen="True">
    <ResponseField name="candidateCount" type="integer" default={1}>
      Number of generated images to return.
    </ResponseField>

    <ResponseField name="temperature" type="number">
      Controls the randomness of the output.
    </ResponseField>

    <ResponseField name="topP" type="number">
      The maximum cumulative probability of tokens to consider when sampling.
    </ResponseField>

    <ResponseField name="topK" type="number">
      The maximum number of tokens to consider when sampling.
    </ResponseField>

    <ResponseField name="maxOutputTokens" type="number">
      The maximum number of tokens to include in a candidate.
    </ResponseField>

    <ResponseField name="stopSequences" type="array">
      A list of sequences that will stop generation.
    </ResponseField>

    <ResponseField name="responseModalities" type="array">
      Allowed modalities of the output. Use `["IMAGE", "TEXT"]`.
    </ResponseField>

    <ResponseField name="imageConfig" type="object">
      Settings for the output image.

      <Expandable title="imageConfig">
        <ResponseField name="aspectRatio" type="string">
          Aspect ratio of the generated image (e.g. `"16:9"`, `"1:1"`).
        </ResponseField>

        <ResponseField name="imageSize" type="string">
          Output image resolution level (e.g. `"1K"`, `"2K"`, `"4K"`).
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField path="safetySettings" type="array">
  A list of unique safety settings for blocking unsafe content.

  <Expandable title="safetySettings[]" defaultOpen="True">
    <ResponseField name="category" type="string">
      The category for this setting.
    </ResponseField>

    <ResponseField name="threshold" type="string">
      The threshold for blocking.
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField path="tools" type="array">
  A list of tools the model may call.

  <Expandable title="tools[]" defaultOpen="True">
    <ResponseField name="googleSearch" type="object">
      Configuration for Google Search grounding.
    </ResponseField>
  </Expandable>
</ParamField>

<ParamField path="toolConfig" type="object">
  Configuration for tools.

  <Expandable title="toolConfig" defaultOpen="True">
    <ResponseField name="functionCallingConfig" type="object">
      Configuration for function calling.

      <Expandable title="functionCallingConfig" defaultOpen="True">
        <ResponseField name="mode" type="string">
          The function calling mode (e.g. `AUTO`).
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ParamField>

***

## Params to Avoid

| Param                                                   | Reason                                                                                                                                      |
| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `prompt`, `n`, `size`, `quality`                        | OpenAI/Azure OpenAI parameters; sending these at the root level will fail schema validation. Use `contents` and `generationConfig` instead. |
| `response_format`, `output_format`                      | Not supported by the Gemini API. Response format is determined by `responseModalities`.                                                     |
| `background`, `output_compression`, `style`             | OpenAI/Azure specific parameters; not supported by Gemini models.                                                                           |
| `generationConfig.responseMimeType: "application/json"` | Not supported when `responseModalities` includes `"IMAGE"`.                                                                                 |
| `google_search`                                         | Snake case is used in the Gemini Developer API, but the Vertex AI API requires camelCase (`googleSearch`).                                  |
| `spend-logs-metadata`                                   | This metadata must be passed as an HTTP header, not in the JSON request body                                                                |

<Warning>
  Ensure you do not mix OpenAI or Azure-specific parameters (such as `prompt`, `size`, `quality`, or `n`) with Gemini/Vertex AI request structure. Vertex AI expects prompt text inside the nested `contents.parts` object using camelCase keys.
</Warning>

***
