JUHE API Marketplace

Nano Banana 2 API Quick Start on WisGate: 3 Minutes

5 min read
By Chloe Anderson

AI Image API for Developers: What You Need to Know First

  • Model ID: gemini-3.1-flash-image-preview
  • Endpoint: Gemini-native only; not OpenAI-compatible
  • Auth header: use x-goog-api-key, not Authorization: Bearer
  • Output format: Base64 inline data; image URL not provided

Get your API key at https://wisgate.ai/hall/tokens. Test this exact working call live at https://wisgate.ai/studio/image.


Nano Banana 2 on WisGate: The Minimal Working cURL Call

curl
curl -s -X POST \
  "https://wisgate.ai/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
  -H "x-goog-api-key: $WISDOM_GATE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [{"text": "A red fox sitting in a snowy forest, photorealistic"}]
    }],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageConfig": {
        "aspectRatio": "1:1",
        "imageSize": "1K"
      }
    }
  }' \
  | jq -r '.candidates[0].content.parts[0].inlineData.data' \
  | base64 --decode > output.png
  • Endpoint: generateContent is the sole supported method for this model
  • Auth: x-goog-api-key header; $WISDOM_GATE_KEY is your WisGate API key from wisgate.ai/hall/tokens
  • responseModalities: ["IMAGE"]: image data only; see next section for why this matters
  • Decode: jq extracts Base64 string; base64 --decode saves binary as output.png

Generation time is a consistent 20 seconds regardless of resolution. The output.png appears after the call completes in your current directory.


responseModalities: The Parameter That Trips Most Integrations

ValueOutputWhen to Use
["IMAGE"]Image data only, no textDefault for image generation; needed for inline data only
["TEXT","IMAGE"]Both text and image partsWhen you want captions or explanations alongside images

The most common mistake is omitting responseModalities or setting it to ["TEXT"]. This returns text-only responses; image extraction fails and files are empty or corrupt.

Always set responseModalities explicitly to avoid silent failures.


Nano Banana 2 API Integration: imageConfig Parameter Reference

ParameterTypeValid ValuesDefaultNotes
aspectRatiostring"1:1", "4:3", "3:4", "16:9", "9:16", "1:4", "4:1", "1:8", "8:1""1:1"Extended aspect ratios (1:4, 4:1, 1:8, 8:1) are Nano Banana 2 additions
imageSizestring"0.5K", "1K", "2K", "4K""1K"Larger sizes increase Base64 size and cost; see wisgate.ai/models

Full call with explicit imageConfig:

curl
curl -s -X POST \
  "https://wisgate.ai/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
  -H "x-goog-api-key: $WISDOM_GATE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [{"text": "YOUR PROMPT HERE"}]
    }],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageConfig": {
        "aspectRatio": "16:9",
        "imageSize": "2K"
      }
    }
  }' \
  | jq -r '.candidates[0].content.parts[0].inlineData.data' \
  | base64 --decode > output.png

Generation takes about 20 seconds regardless of imageSize. Plan your client timeout accordingly.

Price per image on WisGate is $0.058, $0.010 less than Google's official $0.068 rate. That difference amounts to $10 per 1,000 images, $1,000 per 100,000.

See WisGate model catalog for current pricing and specs.


Using responseModalities: ["TEXT", "IMAGE"] for Combined Output

When you need image plus a text description:

curl
curl -s -X POST \
  "https://wisgate.ai/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
  -H "x-goog-api-key: $WISDOM_GATE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{
      "parts": [{"text": "Generate a product thumbnail for noise-cancelling headphones and a 1-sentence alt text."}]
    }],
    "generationConfig": {
      "responseModalities": ["TEXT", "IMAGE"],
      "imageConfig": {"aspectRatio": "1:1", "imageSize": "1K"}
    }
  }' > response.json

# Extract image
jq -r '.candidates[0].content.parts[] | select(.inlineData) | .inlineData.data' response.json \
  | base64 --decode > output.png

# Extract text
jq -r '.candidates[0].content.parts[] | select(.text) | .text' response.json

Separate jq filters distinguish image and text parts reliably because their order may vary.


Nano Banana 2 API Integration: Python and Node.js Equivalents

Python example:

python
import requests, base64, os

response = requests.post(
    "https://wisgate.ai/v1beta/models/gemini-3.1-flash-image-preview:generateContent",
    headers={
        "x-goog-api-key": os.environ["WISDOM_GATE_KEY"],
        "Content-Type": "application/json"
    },
    json={
        "contents": [{"parts": [{"text": "YOUR PROMPT HERE"}]}],
        "generationConfig": {
            "responseModalities": ["IMAGE"],
            "imageConfig": {"aspectRatio": "1:1", "imageSize": "1K"}
        }
    },
    timeout=30
)

parts = response.json()["candidates"][0]["content"]["parts"]
image_data = next(p["inlineData"]["data"] for p in parts if "inlineData" in p)
with open("output.png", "wb") as f:
    f.write(base64.b64decode(image_data))

Node.js example:

fetch
import fetch from "node-fetch";
import { writeFileSync } from "fs";

const res = await fetch(
  "https://wisgate.ai/v1beta/models/gemini-3.1-flash-image-preview:generateContent",
  {
    method: "POST",
    headers: {
      "x-goog-api-key": process.env.WISDOM_GATE_KEY,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      contents: [{ parts: [{ text: "YOUR PROMPT HERE" }] }],
      generationConfig: {
        responseModalities: ["IMAGE"],
        imageConfig: { aspectRatio: "1:1", imageSize: "1K" }
      }
    })
  }
);

const data = await res.json();
const parts = data.candidates[0].content.parts;
const imageData = parts.find(p => p.inlineData)?.inlineData.data;
writeFileSync("output.png", Buffer.from(imageData, "base64"));

Ensure your HTTP client timeout is at least 30 seconds to cover the 20-second generation plus latency.


Common Integration Errors and Fixes

SymptomCauseFix
null from jq extractionMissing or wrong responseModalitiesExplicitly set responseModalities to ["IMAGE"]
Empty or corrupt fileNull Base64 string due to extraction errorValidate jq path and check responseModalities
401 UnauthorizedUsing Authorization: Bearer headerSwitch to x-goog-api-key header
Request timeoutClient timeout less than 20 secondsIncrease timeout to 30 seconds minimum
400 Bad RequestInvalid aspectRatio or imageSizeUse only valid values from the parameter table

Nano Banana 2 API Integration: What to Build Next

The working cURL example is fully detailed above. The imageConfig parameters and error reference prepare you for most use cases.

Try the call live at https://wisgate.ai/studio/image. Get your API key at https://wisgate.ai/hall/tokens.

At $0.058/image with a stable 20-second response, one WisGate key covers text and image generation.

Begin by generating your key and running the minimal call to confirm your integration.

Nano Banana 2 API Quick Start on WisGate: 3 Minutes | JuheAPI