Nano Banana 2 API 사용법: API 키, 요청, 결과 받기
Nano Banana 2 API를 단계별로 사용하는 방법: API 키 발급, generateContent 요청 전송, 작업 폴링, 참조 이미지 추가, 코딩 에이전트로 실행하기까지 정리합니다.
Markdown으로 읽기Nano Banana 2 API를 사용하려면 API 키를 발급받고, Google의 generateContent 요청 본문에 model 필드를 더해 하나의 엔드포인트로 보낸 뒤, 반환된 작업을 이미지 URL이 준비될 때까지 폴링하면 됩니다. Nano Banana Pro와 Nano Banana 2 Lite도 같은 단계로 사용하며, model 값만 바뀝니다.
이 가이드는 동작하는 코드로 각 단계를 설명한 뒤, 참조 이미지로 편집하는 방법과 작업을 코딩 에이전트에 맡기는 방법을 보여 줍니다.
첫 요청 전에 무엇이 필요한가요?
- API 키. API 키 페이지에서 발급받고 서버에 보관하세요. 브라우저 코드에는 절대 넣지 마세요.
- 크레딧. 결제 페이지에서 잔액을 충전하세요. 크레딧은 만료되지 않으며, 실패한 요청은 과금되지 않습니다.
- 모델 ID.
gemini-3.1-flash-image는 이미지 1장마다 고정 가격으로,gemini-3.1-flash-image-official은 토큰으로 과금합니다. 선택은 가격 가이드를 참고하세요.
export SEEDROUTER_API_KEY="your-key"Nano Banana 2 요청은 어떻게 보내나요?
/v1/images/generations로 요청을 POST하세요. 본문은 Google의 generateContent 형태에 model을 더한 것입니다.
curl https://api.seedrouter.ai/v1/images/generations \
-H "Authorization: Bearer $SEEDROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image",
"contents": [{"parts": [{"text": "A ceramic teapot on a linen tablecloth, soft window light"}]}],
"generationConfig": {
"responseModalities": ["IMAGE"],
"imageConfig": {"aspectRatio": "16:9", "imageSize": "2K"}
}
}'응답은 이미지가 아니라 작업입니다.
{
"id": "task_...",
"model": "gemini-3.1-flash-image",
"status": "processing",
"created_at": 1790310979
}이미 Google API를 호출하고 있다면, 보내는 본문은 generateContent에 보내던 것과 같습니다. SeedRouter에서 /v1beta/models/...:generateContent를 직접 호출하는 방식은 지원되지 않으므로 이 엔드포인트를 사용하세요.
이미지는 어떻게 받나요?
status가 completed 또는 failed가 될 때까지 몇 초 간격으로 작업을 폴링하세요. Python 예시는 다음과 같습니다.
import os
import time
import requests
API = "https://api.seedrouter.ai/v1"
headers = {"Authorization": f"Bearer {os.environ['SEEDROUTER_API_KEY']}"}
response = requests.post(
f"{API}/images/generations",
headers=headers,
json={
"model": "gemini-3.1-flash-image",
"contents": [{"parts": [{"text": "A ceramic teapot on a linen tablecloth, soft window light"}]}],
"generationConfig": {
"responseModalities": ["IMAGE"],
"imageConfig": {"aspectRatio": "16:9", "imageSize": "2K"},
},
},
timeout=60,
)
response.raise_for_status()
task_id = response.json()["id"]
deadline = time.monotonic() + 600
while time.monotonic() < deadline:
result = requests.get(f"{API}/tasks/{task_id}", headers=headers, timeout=30)
result.raise_for_status()
task = result.json()
if task["status"] == "completed":
for image in task["output"]["data"]:
print(image["url"])
break
if task["status"] == "failed":
raise RuntimeError(task["error"]["message"])
time.sleep(3)
else:
raise TimeoutError(f"Still waiting. Resume polling task {task_id}.")완료된 작업의 output.data[0].url에 이미지 URL이 있고, 토큰 사용량도 함께 담깁니다. "responseModalities": ["TEXT", "IMAGE"]를 쓰면 모델이 작성한 텍스트가 output.text로 반환됩니다. 장기간 필요하다면 이미지를 자체 스토리지에 내려받으세요.
폴링 중 타임아웃이 났다고 해서 이미지 생성이 실패한 것은 아닙니다. 작업 ID를 보관하고 다시 확인하세요. 새 요청을 제출하면 두 번째 이미지 비용을 내게 됩니다.
이미지 편집이나 참조 이미지는 어떻게 쓰나요?
텍스트 옆에 fileData 파트를 추가하세요. 각 파트는 공개 URL과 그 MIME 타입으로 구성됩니다.
curl https://api.seedrouter.ai/v1/images/generations \
-H "Authorization: Bearer $SEEDROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-3.1-flash-image",
"contents": [{
"role": "user",
"parts": [
{"text": "Turn this photo into a watercolor painting. Keep the composition."},
{"fileData": {"mimeType": "image/jpeg", "fileUri": "https://example.com/photo.jpg"}}
]
}]
}'Nano Banana 2는 요청당 최대 14개의 참조를 받습니다. 이미지, 동영상, PDF를 받으며 각각 50 MB 미만이어야 합니다. 참조는 URL이어야 하며 base64 inlineData는 받지 않습니다. URL을 가져올 수 없으면 작업이 실패하고 과금되지 않습니다. 후속 편집을 하려면 이전 턴을 user와 model 항목으로 보내고 새 user 턴으로 끝내세요.
가장 중요한 설정은 무엇인가요?
| 설정 | 역할 |
|---|---|
imageConfig.imageSize | 512, 1K, 2K, 4K 중 하나, 기본값 1K |
imageConfig.aspectRatio | 1:8부터 8:1까지 14가지 비율, 생략하면 첫 번째 참조를 따름 |
responseModalities | 이미지만 받으려면 ["IMAGE"], 텍스트도 받으려면 ["TEXT", "IMAGE"] |
systemInstruction | 하우스 스타일 같은 고정 규칙 |
seed | 재사용하면 이전 결과에 더 가깝게 생성 |
mediaResolution | 참조 하나가 사용하는 토큰 수, 낮을수록 Official에서 저렴 |
Nano Banana 2 API 레퍼런스에 모든 필드와 한도가 나와 있습니다. 알 수 없는 필드는 과금 전에 거부되며, Google Search grounding(tools)은 아직 제공되지 않습니다.
코딩 에이전트가 Nano Banana 2 API를 쓰게 하려면?
Claude Code, Codex, Cursor 같은 코딩 에이전트는 셸 명령이나 짧은 스크립트로 API를 호출할 수 있습니다. SeedRouter는 MCP 서버나 패키지형 skill을 제공하지 않으며, 아래 프롬프트가 연동의 전부입니다. 먼저 키를 export한 뒤 붙여 넣으세요.
Use the SeedRouter API to generate a Nano Banana 2 image for me.
Security: read SEEDROUTER_API_KEY from my local environment. Never ask me to paste it and never print it.
Goal: [subject, setting, style, what the image is for]
Size: [512 | 1K | 2K | 4K] Aspect ratio: [e.g. 1:1, 16:9, 9:16]
References: [public image URLs, or none]
Send POST https://api.seedrouter.ai/v1/images/generations with
{"model": "gemini-3.1-flash-image",
"contents": [{"parts": [{"text": "..."}, {"fileData": {"mimeType": "image/jpeg", "fileUri": "https://..."}}]}],
"generationConfig": {"responseModalities": ["IMAGE"],
"imageConfig": {"aspectRatio": "...", "imageSize": "..."}}}
Accepted top-level fields: model, contents, systemInstruction, safetySettings,
generationConfig. References must be fileData URLs (up to 14), never base64.
Do not add tools or any other field.
Before sending, show me the request body and wait for my approval: each
request is charged. Then poll GET https://api.seedrouter.ai/v1/tasks/{id}
every 3 seconds until status is completed or failed. If polling times out,
keep checking the same task; never resubmit. Save output.data[0].url into
./images/ and tell me the file path.승인 단계가 중요합니다. 에이전트는 사용자의 잔액을 쓰므로 스스로 제출해서는 안 됩니다.
자주 묻는 질문
Nano Banana 2 API 키는 어떻게 발급받나요?
로그인한 뒤 API 키 페이지를 열어 키를 만드세요. 같은 키로 Nano Banana 2, Nano Banana Pro, Nano Banana 2 Lite와 SeedRouter의 다른 모델을 모두 사용할 수 있습니다.
Nano Banana 2 API는 일괄(batch) 요청을 지원하나요?
이미지마다 요청을 하나씩 보내고 작업들을 병렬로 폴링하세요. 요청 하나는 이미지 한 장을 반환하며, 작업마다 따로 과금됩니다.
어떤 오류를 처리해야 하나요?
400은 알 수 없는 필드나 지원하지 않는 크기처럼 본문이 규칙을 어겼다는 뜻이며, 과금되지 않습니다. failed로 끝난 작업에는 오류 메시지가 담기며 역시 과금되지 않습니다. 오류 가이드에 모든 코드와 재시도 시점이 정리되어 있습니다.
첫 요청을 보내 보세요
키를 발급받고 소액을 충전한 뒤 위의 Python 예제를 실행하거나, Nano Banana 2 Playground에서 코드 없이 같은 요청을 시험해 보세요. 복잡한 프롬프트에는 모델을 gemini-3-pro-image로 바꿔 Nano Banana Pro를 사용하세요.



