gemini-2.5-flash-image-preview, via cometapi for image generation. It covers two common methods:generateContent API for text-to-image generationgenerateContent API for image-to-image generation (both input and output are Base64)sk-xxxx in the examples with your cometapi key. For security, do not expose your key in client-side code or public repositories.Authorization header for cometapi typically uses the key value directly, e.g., Authorization: sk-xxxx.inline_data. You will need to decode it on the client side and save it as a file.https://api.cometapi.comgemini-2.5-flash-image-preview / gemini-2.5-flash-imagegenerateContent for Text-to-ImagegenerateContent endpoint for text-to-image generation. Place the text prompt in contents.parts[].text.^ for line continuation):response.candidates[0].content.parts, which can contain:{ "text": "..." }{ "inline_data": { "mime_type": "image/png", "data": "<base64>" } }data field (the Base64 string) and save it as a file with the corresponding extension.generateContent for Image-to-Image (Base64 I/O)inline_data.data. Do not include prefixes like data:image/jpeg;base64,.candidates[0].content.parts and includes:inline_data (where data is the Base64 of the output image).inline_data.data (do not include prefixes like data:image/jpeg;base64,).candidates[0].content.parts and contains:inline_data (where data is the Base64 of the output image){
"candidates": [
{
"content": {
"parts": [
{ "text": "..." },
{
"inlineData": {
"mimeType": "image/png",
"data": "<base64-string>"
}
}
]
}
}
]
}inlineData.data string and choose the file extension based on its mimeType (e.g., .png, .jpg, .webp).Authorization: sk-xxxx. Please refer to the official cometapi documentation for confirmation.data:image/png;base64, in the data field; only include the pure Base64 data string.4xx errors usually indicate issues with request parameters or authentication (check your key, model name, JSON format). 5xx errors are server-side problems (you can retry later or contact support).gemini-2.5-flash-image-preview via cometapi. Choose the API style that suits your needs and implement the Base64 image decoding and display on the client side.gemini-2.5-flash-image. The previous gemini-2.5-flash-image-preview will be deprecated."responseModalities" to ["IMAGE"] only in API requests. This ensures image generation without text-only responses.