# model can be "gemini-3.1-flash-image-preview", or the compatible alias "nano-banana-2-ext"curl --request POST \ --url https://api.apimart.ai/v1/images/generations \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "model": "gemini-3.1-flash-image-preview", "prompt": "Cyberpunk cityscape at night with neon lights", "size": "16:9", "resolution": "2K", "n": 1 }'
import Foundationlet url = URL(string: "https://api.apimart.ai/v1/images/generations")!let payload: [String: Any] = [ "model": "gemini-3.1-flash-image-preview", "prompt": "Cyberpunk cityscape at night with neon lights", "size": "16:9", "resolution": "2K", "n": 1]var request = URLRequest(url: url)request.httpMethod = "POST"request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")request.setValue("application/json", forHTTPHeaderField: "Content-Type")request.httpBody = try? JSONSerialization.data(withJSONObject: payload)let task = URLSession.shared.dataTask(with: request) { data, response, error in if let error = error { print("Error: \(error)") return } if let data = data, let responseString = String(data: data, encoding: .utf8) { print(responseString) }}task.resume()
using System;using System.Net.Http;using System.Text;using System.Threading.Tasks;class Program{ static async Task Main(string[] args) { var url = "https://api.apimart.ai/v1/images/generations"; var payload = @"{ ""model"": ""gemini-3.1-flash-image-preview"", ""prompt"": ""Cyberpunk cityscape at night with neon lights"", ""size"": ""16:9"", ""resolution"": ""2K"", ""n"": 1 }"; using var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>"); var content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); var result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); }}
(* Requires cohttp and yojson libraries *)open Lwtopen Cohttpopen Cohttp_lwt_unixlet url = "https://api.apimart.ai/v1/images/generations"let payload = {|{ "model": "gemini-3.1-flash-image-preview", "prompt": "Cyberpunk cityscape at night with neon lights", "size": "16:9", "resolution": "2K", "n": 1}|}let () = let headers = Header.init () |> fun h -> Header.add h "Authorization" "Bearer <token>" |> fun h -> Header.add h "Content-Type" "application/json" in let body = Cohttp_lwt.Body.of_string payload in let response = Client.post ~headers ~body (Uri.of_string url) >>= fun (resp, body) -> body |> Cohttp_lwt.Body.to_string >|= fun body_str -> print_endline body_str in Lwt_main.run response
import 'dart:convert';import 'package:http/http.dart' as http;void main() async { final url = Uri.parse('https://api.apimart.ai/v1/images/generations'); final payload = { 'model': 'gemini-3.1-flash-image-preview', 'prompt': 'Cyberpunk cityscape at night with neon lights', 'size': '16:9', 'resolution': '2K', 'n': 1 }; final response = await http.post( url, headers: { 'Authorization': 'Bearer <token>', 'Content-Type': 'application/json', }, body: jsonEncode(payload), ); print(response.body);}
library(httr)library(jsonlite)url <- "https://api.apimart.ai/v1/images/generations"payload <- list( model = "gemini-3.1-flash-image-preview", prompt = "Cyberpunk cityscape at night with neon lights", size = "16:9", resolution = "2K", n = 1)response <- POST( url, add_headers( Authorization = "Bearer <token>", `Content-Type` = "application/json" ), body = toJSON(payload, auto_unbox = TRUE), encode = "raw")cat(content(response, "text"))
Integrated Google Search enhancement for more realistic image generation
POST
/
v1
/
images
/
generations
# model can be "gemini-3.1-flash-image-preview", or the compatible alias "nano-banana-2-ext"curl --request POST \ --url https://api.apimart.ai/v1/images/generations \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "model": "gemini-3.1-flash-image-preview", "prompt": "Cyberpunk cityscape at night with neon lights", "size": "16:9", "resolution": "2K", "n": 1 }'
import Foundationlet url = URL(string: "https://api.apimart.ai/v1/images/generations")!let payload: [String: Any] = [ "model": "gemini-3.1-flash-image-preview", "prompt": "Cyberpunk cityscape at night with neon lights", "size": "16:9", "resolution": "2K", "n": 1]var request = URLRequest(url: url)request.httpMethod = "POST"request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")request.setValue("application/json", forHTTPHeaderField: "Content-Type")request.httpBody = try? JSONSerialization.data(withJSONObject: payload)let task = URLSession.shared.dataTask(with: request) { data, response, error in if let error = error { print("Error: \(error)") return } if let data = data, let responseString = String(data: data, encoding: .utf8) { print(responseString) }}task.resume()
using System;using System.Net.Http;using System.Text;using System.Threading.Tasks;class Program{ static async Task Main(string[] args) { var url = "https://api.apimart.ai/v1/images/generations"; var payload = @"{ ""model"": ""gemini-3.1-flash-image-preview"", ""prompt"": ""Cyberpunk cityscape at night with neon lights"", ""size"": ""16:9"", ""resolution"": ""2K"", ""n"": 1 }"; using var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>"); var content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); var result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); }}
(* Requires cohttp and yojson libraries *)open Lwtopen Cohttpopen Cohttp_lwt_unixlet url = "https://api.apimart.ai/v1/images/generations"let payload = {|{ "model": "gemini-3.1-flash-image-preview", "prompt": "Cyberpunk cityscape at night with neon lights", "size": "16:9", "resolution": "2K", "n": 1}|}let () = let headers = Header.init () |> fun h -> Header.add h "Authorization" "Bearer <token>" |> fun h -> Header.add h "Content-Type" "application/json" in let body = Cohttp_lwt.Body.of_string payload in let response = Client.post ~headers ~body (Uri.of_string url) >>= fun (resp, body) -> body |> Cohttp_lwt.Body.to_string >|= fun body_str -> print_endline body_str in Lwt_main.run response
import 'dart:convert';import 'package:http/http.dart' as http;void main() async { final url = Uri.parse('https://api.apimart.ai/v1/images/generations'); final payload = { 'model': 'gemini-3.1-flash-image-preview', 'prompt': 'Cyberpunk cityscape at night with neon lights', 'size': '16:9', 'resolution': '2K', 'n': 1 }; final response = await http.post( url, headers: { 'Authorization': 'Bearer <token>', 'Content-Type': 'application/json', }, body: jsonEncode(payload), ); print(response.body);}
library(httr)library(jsonlite)url <- "https://api.apimart.ai/v1/images/generations"payload <- list( model = "gemini-3.1-flash-image-preview", prompt = "Cyberpunk cityscape at night with neon lights", size = "16:9", resolution = "2K", n = 1)response <- POST( url, add_headers( Authorization = "Bearer <token>", `Content-Type` = "application/json" ), body = toJSON(payload, auto_unbox = TRUE), encode = "raw")cat(content(response, "text"))
{ "error": { "code": 500, "message": "Internal server error. Please try again later", "type": "server_error" }}
{ "error": { "code": 502, "message": "Bad gateway. The server is temporarily unavailable", "type": "bad_gateway" }}
Model name compatibility note: This endpoint also accepts the alias nano-banana-2-ext, which is equivalent to gemini-3.1-flash-image-preview. The two are interchangeable and produce identical results.
# model can be "gemini-3.1-flash-image-preview", or the compatible alias "nano-banana-2-ext"curl --request POST \ --url https://api.apimart.ai/v1/images/generations \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "model": "gemini-3.1-flash-image-preview", "prompt": "Cyberpunk cityscape at night with neon lights", "size": "16:9", "resolution": "2K", "n": 1 }'
import Foundationlet url = URL(string: "https://api.apimart.ai/v1/images/generations")!let payload: [String: Any] = [ "model": "gemini-3.1-flash-image-preview", "prompt": "Cyberpunk cityscape at night with neon lights", "size": "16:9", "resolution": "2K", "n": 1]var request = URLRequest(url: url)request.httpMethod = "POST"request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")request.setValue("application/json", forHTTPHeaderField: "Content-Type")request.httpBody = try? JSONSerialization.data(withJSONObject: payload)let task = URLSession.shared.dataTask(with: request) { data, response, error in if let error = error { print("Error: \(error)") return } if let data = data, let responseString = String(data: data, encoding: .utf8) { print(responseString) }}task.resume()
using System;using System.Net.Http;using System.Text;using System.Threading.Tasks;class Program{ static async Task Main(string[] args) { var url = "https://api.apimart.ai/v1/images/generations"; var payload = @"{ ""model"": ""gemini-3.1-flash-image-preview"", ""prompt"": ""Cyberpunk cityscape at night with neon lights"", ""size"": ""16:9"", ""resolution"": ""2K"", ""n"": 1 }"; using var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>"); var content = new StringContent(payload, Encoding.UTF8, "application/json"); var response = await client.PostAsync(url, content); var result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); }}
(* Requires cohttp and yojson libraries *)open Lwtopen Cohttpopen Cohttp_lwt_unixlet url = "https://api.apimart.ai/v1/images/generations"let payload = {|{ "model": "gemini-3.1-flash-image-preview", "prompt": "Cyberpunk cityscape at night with neon lights", "size": "16:9", "resolution": "2K", "n": 1}|}let () = let headers = Header.init () |> fun h -> Header.add h "Authorization" "Bearer <token>" |> fun h -> Header.add h "Content-Type" "application/json" in let body = Cohttp_lwt.Body.of_string payload in let response = Client.post ~headers ~body (Uri.of_string url) >>= fun (resp, body) -> body |> Cohttp_lwt.Body.to_string >|= fun body_str -> print_endline body_str in Lwt_main.run response
import 'dart:convert';import 'package:http/http.dart' as http;void main() async { final url = Uri.parse('https://api.apimart.ai/v1/images/generations'); final payload = { 'model': 'gemini-3.1-flash-image-preview', 'prompt': 'Cyberpunk cityscape at night with neon lights', 'size': '16:9', 'resolution': '2K', 'n': 1 }; final response = await http.post( url, headers: { 'Authorization': 'Bearer <token>', 'Content-Type': 'application/json', }, body: jsonEncode(payload), ); print(response.body);}
library(httr)library(jsonlite)url <- "https://api.apimart.ai/v1/images/generations"payload <- list( model = "gemini-3.1-flash-image-preview", prompt = "Cyberpunk cityscape at night with neon lights", size = "16:9", resolution = "2K", n = 1)response <- POST( url, add_headers( Authorization = "Bearer <token>", `Content-Type` = "application/json" ), body = toJSON(payload, auto_unbox = TRUE), encode = "raw")cat(content(response, "text"))
{ "error": { "code": 500, "message": "Internal server error. Please try again later", "type": "server_error" }}
{ "error": { "code": 502, "message": "Bad gateway. The server is temporarily unavailable", "type": "bad_gateway" }}
Authorizations
string
required
All API endpoints require Bearer Token authenticationGet your API Key:Visit the API Key Management Page to get your API KeyAdd it to the request header:
Authorization: Bearer YOUR_API_KEY
Body
string
default:"gemini-3.1-flash-image-preview"
required
Image generation model nameSupported models:
gemini-3.1-flash-image-preview - Standard version (compatible alias nano-banana-2-ext)
gemini-3.1-flash-image-preview-official - Official version (compatible alias nano-banana-2)
Example: "gemini-3.1-flash-image-preview" or "gemini-3.1-flash-image-preview-official"
For backward compatibility, the aliases nano-banana-2-ext (for gemini-3.1-flash-image-preview) and nano-banana-2 (for gemini-3.1-flash-image-preview-official) remain usable.
boolean
default:"false"
Whether to run content moderation before submitting the image task.
true: use omni-moderation-latest to review prompts and input images
false or omitted: do not send a moderation request, adding no moderation cost or latency (default)
string
required
Text description for image generation
string
Image aspect ratioSupported ratios:
auto - Automatically choose the aspect ratio
1:1 - Square, avatars, social media
3:2 / 2:3 - Standard photos
4:3 / 3:4 - Traditional display ratio
16:9 / 9:16 - Widescreen / vertical video covers
5:4 / 4:5 - Instagram images
21:9 - Ultra-wide banner
1:4 / 4:1 - Long poster / banner
1:8 / 8:1 - Extreme long images / banner ads
For text-to-image, when size is auto, the default is 1:1 or 16:9; for image-to-image, the aspect ratio follows the upstream response. We recommend specifying an aspect ratio.
string
default:"1K"
Output image resolutionSupported values:
0.5K - ~512px, low-resolution preview
1K - ~1024px, standard resolution (default)
2K - ~2048px, high resolution
4K - ~4096px, ultra-high resolution
Note: Different resolutions have different pricing. 4K costs more than 1K.
integer
Number of images to generateRange: 1Default: 1⚠️ Note: Must enter a plain number (e.g., 1), do not use quotes or it will cause an error
boolean
default:"false"
Whether to use the official channel fallback
false: Do not use (default)
true: Use official channel
When using the official channel (gemini-3.1-flash-image-preview-official), this parameter cannot be used.
array
Reference image URL list for image-to-image generationTwo formats are supported:1. Full image URL
Publicly accessible image URL (http:// or https://)