Generate or Edit Image
curl --request POST \
--url https://api.nanobananaapi.ai/api/v1/nanobanana/generate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "A serene mountain landscape at sunset with a lake reflecting the orange sky",
"numImages": 1,
"type": "TEXTTOIAMGE",
"image_size": "16:9",
"callBackUrl": "https://your-callback-url.com/callback"
}
'import requests
url = "https://api.nanobananaapi.ai/api/v1/nanobanana/generate"
payload = {
"prompt": "A serene mountain landscape at sunset with a lake reflecting the orange sky",
"numImages": 1,
"type": "TEXTTOIAMGE",
"image_size": "16:9",
"callBackUrl": "https://your-callback-url.com/callback"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'A serene mountain landscape at sunset with a lake reflecting the orange sky',
numImages: 1,
type: 'TEXTTOIAMGE',
image_size: '16:9',
callBackUrl: 'https://your-callback-url.com/callback'
})
};
fetch('https://api.nanobananaapi.ai/api/v1/nanobanana/generate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.nanobananaapi.ai/api/v1/nanobanana/generate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'A serene mountain landscape at sunset with a lake reflecting the orange sky',
'numImages' => 1,
'type' => 'TEXTTOIAMGE',
'image_size' => '16:9',
'callBackUrl' => 'https://your-callback-url.com/callback'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.nanobananaapi.ai/api/v1/nanobanana/generate"
payload := strings.NewReader("{\n \"prompt\": \"A serene mountain landscape at sunset with a lake reflecting the orange sky\",\n \"numImages\": 1,\n \"type\": \"TEXTTOIAMGE\",\n \"image_size\": \"16:9\",\n \"callBackUrl\": \"https://your-callback-url.com/callback\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.nanobananaapi.ai/api/v1/nanobanana/generate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"A serene mountain landscape at sunset with a lake reflecting the orange sky\",\n \"numImages\": 1,\n \"type\": \"TEXTTOIAMGE\",\n \"image_size\": \"16:9\",\n \"callBackUrl\": \"https://your-callback-url.com/callback\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.nanobananaapi.ai/api/v1/nanobanana/generate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"A serene mountain landscape at sunset with a lake reflecting the orange sky\",\n \"numImages\": 1,\n \"type\": \"TEXTTOIAMGE\",\n \"image_size\": \"16:9\",\n \"callBackUrl\": \"https://your-callback-url.com/callback\"\n}"
response = http.request(request)
puts response.read_body{
"code": 200,
"msg": "success",
"data": {
"taskId": "task12345"
}
}{
"code": 400,
"msg": "Parameter error"
}{
"code": 401,
"msg": "Unauthorized"
}{
"code": 500,
"msg": "Server internal error"
}NanoBanana API
Generate or Edit Image
Submit Nanobanana image generation or editing task using the NanoBanana AI model.
POST
/
api
/
v1
/
nanobanana
/
generate
Generate or Edit Image
curl --request POST \
--url https://api.nanobananaapi.ai/api/v1/nanobanana/generate \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "A serene mountain landscape at sunset with a lake reflecting the orange sky",
"numImages": 1,
"type": "TEXTTOIAMGE",
"image_size": "16:9",
"callBackUrl": "https://your-callback-url.com/callback"
}
'import requests
url = "https://api.nanobananaapi.ai/api/v1/nanobanana/generate"
payload = {
"prompt": "A serene mountain landscape at sunset with a lake reflecting the orange sky",
"numImages": 1,
"type": "TEXTTOIAMGE",
"image_size": "16:9",
"callBackUrl": "https://your-callback-url.com/callback"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'A serene mountain landscape at sunset with a lake reflecting the orange sky',
numImages: 1,
type: 'TEXTTOIAMGE',
image_size: '16:9',
callBackUrl: 'https://your-callback-url.com/callback'
})
};
fetch('https://api.nanobananaapi.ai/api/v1/nanobanana/generate', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.nanobananaapi.ai/api/v1/nanobanana/generate",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'A serene mountain landscape at sunset with a lake reflecting the orange sky',
'numImages' => 1,
'type' => 'TEXTTOIAMGE',
'image_size' => '16:9',
'callBackUrl' => 'https://your-callback-url.com/callback'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.nanobananaapi.ai/api/v1/nanobanana/generate"
payload := strings.NewReader("{\n \"prompt\": \"A serene mountain landscape at sunset with a lake reflecting the orange sky\",\n \"numImages\": 1,\n \"type\": \"TEXTTOIAMGE\",\n \"image_size\": \"16:9\",\n \"callBackUrl\": \"https://your-callback-url.com/callback\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.nanobananaapi.ai/api/v1/nanobanana/generate")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"A serene mountain landscape at sunset with a lake reflecting the orange sky\",\n \"numImages\": 1,\n \"type\": \"TEXTTOIAMGE\",\n \"image_size\": \"16:9\",\n \"callBackUrl\": \"https://your-callback-url.com/callback\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.nanobananaapi.ai/api/v1/nanobanana/generate")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"A serene mountain landscape at sunset with a lake reflecting the orange sky\",\n \"numImages\": 1,\n \"type\": \"TEXTTOIAMGE\",\n \"image_size\": \"16:9\",\n \"callBackUrl\": \"https://your-callback-url.com/callback\"\n}"
response = http.request(request)
puts response.read_body{
"code": 200,
"msg": "success",
"data": {
"taskId": "task12345"
}
}{
"code": 400,
"msg": "Parameter error"
}{
"code": 401,
"msg": "Unauthorized"
}{
"code": 500,
"msg": "Server internal error"
}Usage Modes
-
Text-to-Image Generation
- Provide
promptand settypeto “TEXTTOIAMGE” - Model will generate a new image based on the text description
- Provide
-
Image-to-Image Editing
- Provide
prompt,imageUrlsand settypeto “IMAGETOIAMGE” - Model will edit the input images according to the prompt
- Provide
Important Notes
- You can generate 1-4 images per request using the
numImagesparameter - Use the
image_sizeparameter to specify the desired aspect ratio for your images - Callback URL (
callBackUrl) is required for receiving task completion notifications - Task completion will be sent to your callback URL via POST request
- Use the Get Task Details endpoint to poll task status if needed
- Choose the appropriate generation type based on your needs:
- TEXTTOIAMGE: Text to Image generation
- IMAGETOIAMGE: Image editing with input images
Authorizations
All APIs require authentication via Bearer Token.
Get API Key:
- Visit API Key Management Page to get your API Key
Usage: Add to request header: Authorization: Bearer YOUR_API_KEY
Note:
- Keep your API Key secure and do not share it with others
- If you suspect your API Key has been compromised, reset it immediately in the management page
Body
application/json
Text prompt describing the desired image or edit.
Example:
"A serene mountain landscape at sunset with a lake reflecting the orange sky"
Generation type:
- TEXTTOIAMGE: Text to Image
- IMAGETOIAMGE: Image Editing
Available options:
IMAGETOIAMGE, TEXTTOIAMGE Example:
"TEXTTOIAMGE"
Callback URL to receive task completion notifications (required)
Example:
"https://your-callback-url.com/callback"
Number of images to generate. Min: 1, Max: 4
Required range:
1 <= x <= 4Example:
1
Array of input image URLs for image editing mode
Example:
["https://example.com/input-image.jpg"]
Watermark text to add to generated images
Example:
"NanoBanana"
Image aspect ratio. Supported ratios:
- 1:1: Square
- 9:16: Portrait (mobile)
- 16:9: Landscape (widescreen)
- 3:4: Portrait
- 4:3: Landscape (traditional)
- 3:2: Landscape (photo)
- 2:3: Portrait (photo)
- 5:4: Portrait (close to square)
- 4:5: Portrait (close to square)
- 21:9: Ultra-wide landscape
Available options:
1:1, 9:16, 16:9, 3:4, 4:3, 3:2, 2:3, 5:4, 4:5, 21:9 Example:
"1:1"