> ## 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.

# Gemini Image editing

# Image editing using Google GenAI SDK

<CodeGroup>
  ```typescript cURL theme={null}
  curl --location 'https://api.znapai.com/gemini/v1beta/models/gemini-3.1-flash-image-preview:generateContent' \
  --header 'x-goog-api-key: $ZnapAI_API_KEY' \
  --header 'Content-Type: application/json' \
  --header 'spend-logs-metadata: {"user_id": "user-123", "project_id": "proj_abc", "env": "production"}' \
  --data '{
        "contents": [{
          "parts":[
              {"text": "Edit this image and draw a yellow smiley in it"},
              {
                "inline_data": {
                  "mime_type":"image/jpeg",
                  "data": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCABAAEADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwCxRRRXsHAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAf/9k="
                }
              }
          ]
        }]
      }'
  ```
</CodeGroup>

## Input

<Frame>
  <img src="https://mintcdn.com/znapai/evv7zK2wdD9gNlYj/images/image-12.png?fit=max&auto=format&n=evv7zK2wdD9gNlYj&q=85&s=ed85042147a5ffe44edd0d3996854062" alt="Image" width="64" height="64" data-path="images/image-12.png" />
</Frame>

## Response

<Frame>
  <img src="https://mintcdn.com/znapai/evv7zK2wdD9gNlYj/images/candidates_0__content_parts_0__inlineData_data-(2)-1.jpg?fit=max&auto=format&n=evv7zK2wdD9gNlYj&q=85&s=0a5dd17ab2a63296c199cdda7d357dc8" alt="Candidates 0 Content Parts 0 Inline Data Data (2)" width="1024" height="1024" data-path="images/candidates_0__content_parts_0__inlineData_data-(2)-1.jpg" />
</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 instruction prompt for editing.
        </ResponseField>

        <ResponseField name="inline_data" type="object">
          The inline image data to be edited.

          <Expandable title="inline_data" defaultOpen="True">
            <ResponseField name="mime_type" type="string" required>
              The IANA media type of the image (e.g. `image/png`, `image/jpeg`).
            </ResponseField>

            <ResponseField name="data" type="string" required>
              The base64-encoded image bytes.
            </ResponseField>
          </Expandable>
        </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="tools" type="array">
  A list of tools the model may call. Supports `google_search` for search grounding.
</ParamField>

<ParamField path="toolConfig" type="object">
  Tool configuration for any `Tool` specified in the request.

  <Expandable title="toolConfig" defaultOpen="False">
    <ResponseField name="function_calling_config" type="object">
      Configuration for function calling behavior.

      <Expandable title="function_calling_config">
        <ResponseField name="mode" type="string">
          Controls how the model uses the provided functions. One of:

          * `"AUTO"` — model decides whether to call a function or respond
          * `"ANY"` — model must call one of the provided functions
          * `"NONE"` — model must not call any functions
        </ResponseField>

        <ResponseField name="allowed_function_names" type="array">
          Optional. Limits the model to only call functions from this list when `mode` is `"ANY"`.
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ParamField>

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

  <Expandable title="generationConfig" defaultOpen="True">
    <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="candidateCount" type="integer">
      Number of generated responses to return. Currently only `1` is supported for image generation.
    </ResponseField>

    <ResponseField name="responseModalities" type="array">
      Allowed modalities of the output. Use `["TEXT", "IMAGE"]` to request image output.
    </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>

    <ResponseField name="stopSequences" type="array">
      A list of sequences that will stop generation.
    </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 (e.g., `HARM_CATEGORY_HATE_SPEECH`).
    </ResponseField>

    <ResponseField name="threshold" type="string">
      The threshold for blocking (e.g., `BLOCK_MEDIUM_AND_ABOVE`).
    </ResponseField>
  </Expandable>
</ParamField>

***

## Params to Avoid

| Param                                                   | Reason                                                                                                                                         |
| ------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `prompt`, `n`, `size`, `quality`, `stream`              | 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"`.                                                                                    |
| `inlineData`, `mimeType`                                | CamelCase keys are used in the Vertex AI API, but the Gemini Developer API requires snake\_case (`inline_data`, `mime_type`) for inline media. |
| `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 request structure. Gemini expects prompt text and the image input inside the nested `contents.parts` object using snake\_case keys.
</Warning>
