Developer route
Nano Banana 2 API
A route reference built from YingTu’s current model registry. The code sample uses the existing Studio code generator and never includes your real key.
Quickstart
- 1
Create or choose a LaoZhang API Key.
- 2
Copy the current model ID and generated Python example.
- 3
Run one small request and inspect the response before scaling.
Request contract
- Endpoint
- POST /v1beta/models/gemini-3.1-flash-image:generateContent
- Authentication
- Bearer API Key
- Request family
- Gemini native
- Reference images
- Supported
Generated Python request
Replace only the placeholder key and your own prompt. Add reference images through the documented edit path when needed.
gemini-3.1-flash-image
import requests
import base64
# Configuration
API_KEY = "sk-YOUR_API_KEY" # Replace with your API Key
API_URL = "https://api2.laozhang.ai/v1beta/models/gemini-3.1-flash-image:generateContent"
# Request headers
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# Build request payload
payload = {
"contents": [{
"parts": [{"text": "A clean product photo of a matte ceramic coffee mug on a light stone table, soft window light, natural shadows, minimal styling."}]
}],
"generationConfig": {
"responseModalities": ["IMAGE"],
"imageConfig": {
"imageSize": "2K"
}
}
}
# Send request
print("Generating image...")
response = requests.post(API_URL, headers=headers, json=payload, timeout=180)
if response.status_code != 200:
print(f"Error: {response.status_code} - {response.text}")
exit(1)
# Extract and save image
result = response.json()
image_part = None
for candidate in result.get("candidates", []):
for part in candidate.get("content", {}).get("parts", []):
inline_data = part.get("inlineData") or part.get("inline_data")
if inline_data and inline_data.get("data"):
image_part = inline_data
break
if image_part:
break
if not image_part:
print("No image data in response")
print(result)
exit(1)
mime_type = image_part.get("mimeType") or image_part.get("mime_type") or "image/png"
extension = "jpg" if mime_type == "image/jpeg" else "webp" if mime_type == "image/webp" else "png"
output_path = f"output.{extension}"
with open(output_path, "wb") as f:
image_data = image_part["data"]
f.write(base64.b64decode(image_data))
print(f"✅ Image saved: {output_path}")
Confirm live pricing, balance, and access in your LaoZhang account before a production run.
Pricing authority
The model registry shows YingTu’s configured per-call estimate. Your LaoZhang account is the authority for live pricing, balance, access, and charges.
Route receipt
- Model ID
- gemini-3.1-flash-image
- Configured estimate
- $0.055/ call
- Output sizes
- 512 · 1K · 2K · 4K
- API family
- Gemini native
Test this model in Studio
Values on this page come from the same model registry used by the Image Studio.
YingTu · LaoZhang