Image editing using Google GenAI SDK
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="
}
}
]
}]
}'
Input

Response
-1.jpg?fit=max&auto=format&n=evv7zK2wdD9gNlYj&q=85&s=0a5dd17ab2a63296c199cdda7d357dc8)
Parameters
header
An optional header used for spend logging metadata, containing JSON properties like
user_id, project_id, and env.array
required
The conversation history or input prompts as an array of content objects.
Show contents[]
Show contents[]
string
The role of the creator of the content (e.g.
"user" or "model").array
required
An ordered list of parts that constitute a single message turn.
object
array
A list of tools the model may call. Supports
google_search for search grounding.object
Tool configuration for any
Tool specified in the request.Show toolConfig
Show toolConfig
object
Configuration for function calling behavior.
Show function_calling_config
Show function_calling_config
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
array
Optional. Limits the model to only call functions from this list when
mode is "ANY".object
Configuration options for the generation.
Show generationConfig
Show generationConfig
number
Controls the randomness of the output.
number
The maximum cumulative probability of tokens to consider when sampling.
number
The maximum number of tokens to consider when sampling.
number
The maximum number of tokens to include in a candidate.
integer
Number of generated responses to return. Currently only
1 is supported for image generation.array
Allowed modalities of the output. Use
["TEXT", "IMAGE"] to request image output.object
array
A list of sequences that will stop generation.
array
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 |
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.