moeru-ai/airi · error · Error

Nano Banana API Error

Error message

Nano Banana API Error

What it means

Thrown by the Nano Banana provider's generation flow when the API response JSON contains an error object. The error.message is used if present, otherwise the generic 'Nano Banana API Error'. The request POSTs a Gemini-style contents payload with imageConfig and reads the response JSON synchronously.

Source

Thrown at apps/stage-tamagotchi/src/main/services/airi/widgets/providers/nanobanana.ts:83

    try {
      const url = `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${this.apiKey}`
      const generationParts: any[] = [{ text: prompt }]
      if (base64Image) {
        generationParts.push({ inline_data: { mime_type: 'image/jpeg', data: base64Image } })
      }

      const response = await fetch(url, {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          contents: [{ parts: generationParts }],
          generationConfig: { imageConfig: { aspectRatio: '1:1', imageSize: resolution } },
        }),
      })

      const json = await response.json()
      if (json.error) {
        throw new Error(json.error.message || 'Nano Banana API Error')
      }

      // Search all parts for the first image
      const responseParts = json.candidates?.[0]?.content?.parts || []
      const imagePart = responseParts.find((p: any) => p.inlineData?.data)
      const inlineData = imagePart?.inlineData

      if (inlineData?.data) {
        const dataUrl = `data:${inlineData.mimeType};base64,${inlineData.data}`
        this.updateStatus(jobId, { status: 'succeeded', progress: 100, imageUrl: dataUrl })
      }
      else {
        throw new Error('No image data returned from Nano Banana')
      }
    }
    catch (e: any) {
      log.error(`[Nano Banana] Generation failed: ${e.message}`)
      this.updateStatus(jobId, { status: 'failed', error: e.message })

View on GitHub (pinned to 27111382b4)

Solutions

  1. Read json.error.message to get the provider's specific failure reason and address it.
  2. Verify the API key is valid and has the Nano Banana (Gemini image) model enabled.
  3. Check quota/billing on the Google AI project and upgrade or wait for quota reset.
  4. Sanitize the prompt and image input to avoid content-filter rejections.
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate key/quota assumptions before calling (best-effort)
if (!this.apiKey) throw new Error('Nano Banana API Key not configured')
// cannot fully pre-validate server-side errors; rely on response handling

Type guard

function isNanoBananaError(json: any): boolean {
  return Boolean(json && typeof json === 'object' && json.error)
}

Try / catch

try {
  return await provider.generate(request)
} catch (e) {
  const msg = errorMessageFrom(e) ?? ''
  if (/API Key|API Error|quota/i.test(msg)) {
    return { error: `Nano Banana request rejected: ${msg}` }
  }
  throw e
}

Prevention

When it happens

Trigger: The Nano Banana (Gemini image) API returned a 4xx/5xx with a JSON body containing { error: { message } } — invalid API key, quota exceeded, model not available for the key, malformed request, safety/content filter, or billing disabled.

Common situations: API key is invalid or revoked; free-tier quota exhausted; the requested model isn't enabled for the project; the image part format is wrong (base64 cleansing left invalid data); safety filter triggered by the prompt; billing not set up on the Google AI project.

Related errors


AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12). Data as JSON: /api/errors/6f414623cc889135. Report an issue: GitHub.