Nano Banana 2.1 API

The Gemini API model ID is gemini-nano-banana-2.1. With a key from Google AI Studio, your server can send a prompt to generateContent and save the returned image. The examples below cover a text prompt and a photo edit.

모델
0/4000
종횡비
해결

기본 15 + 참조 이미지 0 + 프롬프트 0 = 15 크레딧

참조 이미지와 긴 프롬프트에는 크레딧이 추가될 수 있습니다. 생성하기 전에 합계가 표시됩니다.

골든 아워의 아늑한 커피숍, 35mm 필름 사진, 창문을 통해 들어오는 따뜻한 빛, "OPEN LATE"라고 적힌 창문의 네온사인

예골든 아워의 아늑한 커피숍, 35mm 필름 사진, 창문을 통해 들어오는 따뜻한 빛, "OPEN LATE"라고 적힌 창문의 네온사인

실제 결과

Prompt prototyped in the generator

Prompt prototyped in the generator

A 3D mascot made with Nano Banana 2.1. Use the same prompt in the request below.

이 이미지에 사용한 프롬프트 · 1:1

A friendly 3D banana mascot wearing round sunglasses and headphones, studio lighting, pastel yellow background, animated film style

What this site offers

You can test a prompt in this site’s web generator using site credits. For calls from your own app, create a key for a billing-enabled project in Google AI Studio. Google bills the project that owns the key.

Options that matter

responseModalities must include IMAGE. imageConfig.aspectRatio accepts ratios such as 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 5:4, 4:5 and 21:9, plus the 4:1, 8:1, 1:4 and 1:8 strips. imageConfig.imageSize selects 1K, 2K or 4K. For editing, add up to 14 reference images as inlineData parts before the text part.

The response contains candidates with parts. Image parts carry base64 data in inlineData. Skip any interim images flagged as thoughts when saving the output. If no image comes back, read promptFeedback.blockReason and candidate.finishReason.

Request examples

Set GEMINI_API_KEY in your server environment. The curl and Node.js examples pass it to Google in the x-goog-api-key header.

Text to image with curl. aspectRatio takes the same values as the generator, imageSize is 1K, 2K or 4K.
curl -s "https://generativelanguage.googleapis.com/v1beta/models/gemini-nano-banana-2.1:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{ "text": "A cozy coffee shop at golden hour, 35mm film photo" }]
    }],
    "generationConfig": {
      "responseModalities": ["TEXT", "IMAGE"],
      "imageConfig": { "aspectRatio": "3:2", "imageSize": "2K" }
    }
  }'
The same call from Node.js, saving the first final image to disk.
import { writeFile } from 'node:fs/promises';

const model = 'gemini-nano-banana-2.1';
const res = await fetch(
  `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`,
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-goog-api-key': process.env.GEMINI_API_KEY,
    },
    body: JSON.stringify({
      contents: [{ role: 'user', parts: [{ text: 'A friendly 3D banana mascot, studio lighting' }] }],
      generationConfig: {
        responseModalities: ['TEXT', 'IMAGE'],
        imageConfig: { aspectRatio: '1:1', imageSize: '1K' },
      },
    }),
  }
);
if (!res.ok) throw new Error(await res.text());

const data = await res.json();
const parts = data.candidates?.[0]?.content?.parts ?? [];
// Skip interim "thought" images, keep the final one.
const image = parts.find((p) => p.inlineData?.data && !p.thought);
if (!image) throw new Error('no image returned');

await writeFile('mascot.png', Buffer.from(image.inlineData.data, 'base64'));
Editing: put your photo first as inlineData, then the instruction. A googleSearch tool is optional.
{
  "contents": [{
    "role": "user",
    "parts": [
      { "inlineData": { "mimeType": "image/jpeg", "data": "<base64 of your photo>" } },
      { "text": "Replace the background with a minimalist white studio. Keep the person exactly the same." }
    ]
  }],
  "generationConfig": {
    "responseModalities": ["TEXT", "IMAGE"],
    "imageConfig": { "aspectRatio": "4:5", "imageSize": "2K" }
  },
  "tools": [{ "googleSearch": {} }]
}

진행 방법

  1. 01

    Prototype the prompt

    Use the generator on this page. Settle the prompt, the ratio and the resolution before writing code.

  2. 02

    Create a Gemini API key

    Create the key in Google AI Studio and keep it on your server. Never ship it in browser code.

  3. 03

    Send the request and store the image

    Decode the base64 data and save it to your own storage. Handle errors and blocked prompts explicitly.

팁

  • Keep the key on the server

    Call the API from your backend and expose your own endpoint to the front end.

  • Set timeouts and retries

    Image generation takes longer than a typical API call. Use a generous timeout and retry only on transient errors.

  • Mind the cost of 4K

    Draft at 1K and render the final at 4K, as in the web generator.

자주 묻는 질문

Does NanoBanana 2.1 offer an API?
No. The site is a web generator with credits. To call Nano Banana 2.1 from code, use the Gemini API with your own key.
Which model ID should I use?
Use gemini-nano-banana-2.1. In a generateContent REST request, the model ID goes in the URL between models/ and :generateContent.
How do I get 4K output from the API?
Set generationConfig.imageConfig.imageSize to "4K". Valid values are 1K, 2K and 4K.
Can I edit existing photos through the API?
Yes. Send the photo as an inlineData part followed by the text instruction. The example above shows the shape.

첫 번째 Nano Banana 2.1 이미지 만들기

만들고 싶은 첫 이미지를 설명하고 생성 전에 필요한 총 크레딧을 확인하세요.