How to Generate Images Using Your GCP Account (Vertex AI + Nano Banana)

Want to generate original images from a simple text prompt using your own Google Cloud account? With Vertex AI and Google’s Gemini image model (nicknamed “Nano Banana”), you can turn a sentence into a 1024×1024 image in a single API call — no third-party service, no separate API key, and no design software. This guide walks through the exact, working steps.

What you need before you start

  • A Google Cloud project with billing enabled.
  • The Vertex AI API enabled on that project.
  • The gcloud CLI installed, so you can authenticate without hard-coding keys.

That’s it. Once Vertex AI is enabled, image generation is just one HTTPS request away.

Step 1: Authenticate with Application Default Credentials

Instead of managing an API key, Vertex AI uses your Google identity through Application Default Credentials (ADC). Log in once and gcloud handles the token for you:

gcloud auth application-default login
gcloud config set project YOUR_PROJECT_ID

Now any script on that machine can request a short-lived access token with gcloud auth print-access-token — no secrets stored in your code.

Step 2: Choose the right model

Google offers two image paths on Vertex AI, and the difference matters:

  • Gemini image model (gemini-2.5-flash-image, aka Nano Banana) — available broadly, great at in-image text and edits. This is the one we use below.
  • Imagen (imagen-4.0-generate-001 and friends) — Google’s dedicated photoreal image models, but they require the Imagen model to be enabled on your project. If you get a 404 … does not have access error, your project isn’t enabled for Imagen — use the Gemini image model instead.

Step 3: Generate an image with Python

This example uses only the Python standard library plus gcloud — nothing extra to install. It sends your prompt to the Gemini image model and saves the returned PNG:

import json, base64, subprocess, urllib.request

PROJECT = "YOUR_PROJECT_ID"
MODEL = "gemini-2.5-flash-image"   # Nano Banana
token = subprocess.check_output(
    ["gcloud", "auth", "print-access-token"]).decode().strip()

url = (f"https://aiplatform.googleapis.com/v1/projects/{PROJECT}"
       f"/locations/global/publishers/google/models/{MODEL}:generateContent")
body = {"contents": [{"role": "user",
        "parts": [{"text": "Generate an image of a friendly robot watering a plant, flat vector style, no text"}]}]}

req = urllib.request.Request(url, data=json.dumps(body).encode(),
        headers={"Authorization": f"Bearer {token}",
                 "Content-Type": "application/json"})
data = json.loads(urllib.request.urlopen(req).read())

parts = data["candidates"][0]["content"]["parts"]
img = next(p for p in parts if "inlineData" in p)
open("output.png", "wb").write(base64.b64decode(img["inlineData"]["data"]))
print("Saved output.png")

Run it, and you’ll get an output.png in seconds. Prefer the official SDK? Install google-genai and point the client at Vertex (vertexai=True) — the same credentials work.

Tips for better results

  • Describe subject, style, and palette. “Flat vector style,” “photorealistic,” or “soft blue and white palette” all steer the output.
  • Say “no text” unless you specifically want words — AI can misspell in-image text.
  • Iterate. Small prompt changes produce big visual changes; regenerate until it fits.

A note on responsible use

Images from Google’s models carry an invisible SynthID watermark, and it’s good practice to disclose AI-generated visuals. Avoid depicting real, identifiable people or copyrighted logos and characters.

Wrapping up

With Vertex AI and the Gemini image model, your existing Google Cloud account becomes a text-to-image engine you fully control — billed to your own project, authenticated with your own identity, and callable from any script. Enable the API, log in with gcloud, and you’re generating images today.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *