Gemini generateContent Format
In this page's examples, {BASE_URL} is https://api.uniall.ai.
Use this format with Gemini-style clients or when you need Base64 image input and output. The model is part of the URL, and image controls belong in generationConfig.imageConfig.
Endpoint
POST /v1beta/models/{model}:generateContent
Replace {model} with nano-banana-2, nano-banana-pro, or nano-banana-2-lite.
Authentication
x-api-key: sk-***
Content-Type: application/json
The same UniAll API key works for the OpenAI Images and Gemini formats.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
contents | array | Yes | Conversation content containing one user message. |
contents[].role | string | Yes | Use user. |
contents[].parts[].text | string | Yes | Generation or editing instruction. |
contents[].parts[].inlineData | object | Conditional | Reference image for editing. Repeat the part for multiple images. |
inlineData.mimeType | string | Conditional | Image media type, such as image/png. |
inlineData.data | string | Conditional | Raw Base64 data without a Data URL prefix. |
generationConfig.responseModalities | string[] | Yes | Use ["TEXT", "IMAGE"] when text and image output are acceptable. |
generationConfig.imageConfig.imageSize | string | No | 512, 1K, 2K, or 4K; defaults to 1K. Model limits apply. |
generationConfig.imageConfig.aspectRatio | string | No | Output ratio such as 1:1, 3:4, or 16:9. |
| Model | Supported imageSize values |
|---|---|
nano-banana-2 | 512, 1K, 2K, 4K |
nano-banana-pro | 1K, 2K, 4K |
nano-banana-2-lite | 1K |
Text-To-Image Example
curl -X POST "{BASE_URL}/v1beta/models/nano-banana-2:generateContent" \
-H "x-api-key: sk-***" \
-H "Content-Type: application/json" \
-d '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "A cinematic product photo of a clear perfume bottle on black stone, blue mist, no text"
}
]
}
],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {
"imageSize": "512",
"aspectRatio": "1:1"
}
}
}'
Image Editing Example
Encode the image as raw Base64 before building the JSON request:
IMAGE_BASE64="$(base64 < ./reference.png | tr -d '\n')"
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Keep the subject and composition; replace the background with a rainy neon street"
},
{
"inlineData": {
"mimeType": "image/png",
"data": "BASE64_IMAGE_DATA"
}
}
]
}
],
"generationConfig": {
"responseModalities": [
"TEXT",
"IMAGE"
],
"imageConfig": {
"imageSize": "2K",
"aspectRatio": "3:4"
}
}
}
Add another inlineData part for each additional reference image. Keep the image order consistent with the prompt.
Response Example
{
"candidates": [
{
"content": {
"role": "model",
"parts": [
{
"text": "Image generated."
},
{
"inlineData": {
"mimeType": "image/png",
"data": "iVBORw0KGgoAAAANSUhEUgAA..."
}
}
]
},
"finishReason": "STOP"
}
]
}
Find the part containing inlineData, Base64-decode its data, and save it using the returned mimeType. Some clients may normalize the field names to inline_data and mime_type.
Python Example
import base64
import requests
response = requests.post(
"https://api.uniall.ai/v1beta/models/nano-banana-2:generateContent",
headers={"x-api-key": "sk-***", "Content-Type": "application/json"},
json={
"contents": [{
"role": "user",
"parts": [{"text": "An orange cat wearing an astronaut helmet"}],
}],
"generationConfig": {
"responseModalities": ["TEXT", "IMAGE"],
"imageConfig": {"imageSize": "512", "aspectRatio": "1:1"},
},
},
timeout=600,
)
response.raise_for_status()
for candidate in response.json().get("candidates", []):
for part in candidate.get("content", {}).get("parts", []):
image = part.get("inlineData") or part.get("inline_data")
if image and image.get("data"):
with open("generated.png", "wb") as output:
output.write(base64.b64decode(image["data"]))
raise SystemExit(0)
raise RuntimeError("response did not contain an image")
Legacy Model IDs
Earlier Gemini preview IDs that encode a fixed resolution may remain accepted for compatibility. They are deprecated and may be removed at any time. New integrations should use a unified Nano model in the URL and select imageSize in the request.
Billing Notes
Billing depends on the model and imageSize. Check the current model price available to your account. The response may be large because it contains Base64 image data.
Common Errors
- Sending
imageSize: "0.5k"or"512K"; use"512"for 0.5K. - Requesting
512fromnano-banana-proornano-banana-2-lite. - Including
data:image/png;base64,ininlineData.data. - Looking only at the first response part instead of finding the part with
inlineData. - Logging the full Base64 response or API key.