Skip to main content
POST
/
api
/
v1
/
nanobanana
/
generate-2
Generate Image (Nanobanana 2)
curl --request POST \
  --url https://api.nanobananaapi.ai/api/v1/nanobanana/generate-2 \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "prompt": "a happy dog running in the park",
  "imageUrls": [],
  "aspectRatio": "auto",
  "resolution": "1K",
  "googleSearch": false,
  "outputFormat": "jpg",
  "callBackUrl": "https://example-callback.com"
}
'
import requests

url = "https://api.nanobananaapi.ai/api/v1/nanobanana/generate-2"

payload = {
"prompt": "a happy dog running in the park",
"imageUrls": [],
"aspectRatio": "auto",
"resolution": "1K",
"googleSearch": False,
"outputFormat": "jpg",
"callBackUrl": "https://example-callback.com"
}
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 happy dog running in the park',
imageUrls: [],
aspectRatio: 'auto',
resolution: '1K',
googleSearch: false,
outputFormat: 'jpg',
callBackUrl: 'https://example-callback.com'
})
};

fetch('https://api.nanobananaapi.ai/api/v1/nanobanana/generate-2', 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-2",
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 happy dog running in the park',
'imageUrls' => [

],
'aspectRatio' => 'auto',
'resolution' => '1K',
'googleSearch' => false,
'outputFormat' => 'jpg',
'callBackUrl' => 'https://example-callback.com'
]),
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-2"

payload := strings.NewReader("{\n \"prompt\": \"a happy dog running in the park\",\n \"imageUrls\": [],\n \"aspectRatio\": \"auto\",\n \"resolution\": \"1K\",\n \"googleSearch\": false,\n \"outputFormat\": \"jpg\",\n \"callBackUrl\": \"https://example-callback.com\"\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-2")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"a happy dog running in the park\",\n \"imageUrls\": [],\n \"aspectRatio\": \"auto\",\n \"resolution\": \"1K\",\n \"googleSearch\": false,\n \"outputFormat\": \"jpg\",\n \"callBackUrl\": \"https://example-callback.com\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.nanobananaapi.ai/api/v1/nanobanana/generate-2")

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 happy dog running in the park\",\n \"imageUrls\": [],\n \"aspectRatio\": \"auto\",\n \"resolution\": \"1K\",\n \"googleSearch\": false,\n \"outputFormat\": \"jpg\",\n \"callBackUrl\": \"https://example-callback.com\"\n}"

response = http.request(request)
puts response.read_body
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}

Important Notes

  • Task ID returned in the response is used to query task status via the Get Task Details endpoint
  • If callBackUrl is provided, task completion notifications will be sent to that URL via POST request
  • The prompt field supports up to 20,000 characters; more detailed prompts generally produce better results
  • When imageUrls is an empty array, the request runs in pure text-to-image mode; when URLs are provided, it runs in image-to-image / reference mode
  • You can control the aspect ratio, resolution, and output format using aspectRatio, resolution, and outputFormat

Parameter Overview

  • prompt: Text prompt (required), up to 20,000 characters
  • imageUrls: Array of reference image URLs; use an empty array for text-to-image mode, up to 14 images
  • aspectRatio: Aspect ratio of the generated image. Supported: 1:1, 1:4, 1:8, 2:3, 3:2, 3:4, 4:1, 4:3, 4:5, 5:4, 8:1, 9:16, 16:9, 21:9, auto
  • resolution: Output quality level, one of 1K / 2K / 4K
  • googleSearch: Whether to enable Google Web Search grounding (default: false)
  • outputFormat: Output format, either png or jpg (default: jpg)
  • callBackUrl: Optional callback URL to receive async task completion notifications

Authorizations

Authorization
string
header
required

All APIs require authentication via Bearer Token.

Get API Key:

  1. 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
prompt
string
required

Text prompt for image generation (required). Controls the content and style of the generated image. Maximum length: 20,000 characters.

Maximum string length: 20000
Example:
["a happy dog running in the park"]
imageUrls
string<uri>[]

Image URLs for image-to-image mode. Use an empty array for pure text-to-image generation. Supports up to 14 reference images.

Maximum array length: 14
aspectRatio
enum<string>
default:auto

Aspect ratio of the generated image.

Available options:
1:1,
1:4,
1:8,
2:3,
3:2,
3:4,
4:1,
4:3,
4:5,
5:4,
8:1,
9:16,
16:9,
21:9,
auto
resolution
enum<string>
default:1K

Output resolution quality. Higher values produce larger and sharper images at higher cost.

Available options:
1K,
2K,
4K

Use Google Web Search grounding to generate images based on real-time information.

outputFormat
enum<string>
default:jpg

Output image format.

Available options:
png,
jpg
callBackUrl
string<uri>

Optional callback URL for async notifications when the task is completed.

Response

200 - application/json

Request successful

code
integer

Response status code

Example:

200

message
string

Response message

Example:

"success"

data
object