Generate Images

November 17, 2025

Table of contents

  1. Model Capabilities
  2. Request Headers
  3. Request Body
  4. Responses
  5. Model
  6. Examples
  7. Try It

Generate images using Google Flow AI models (Imagen 4, Nano Banana / Gemini 2.5 Flash Image) from text prompts with optional style and context reference images. Generated images are returned as base64-encoded JPEG data.

This endpoint features dynamic concurrency management, allowing anywhere from 3 to 20 parallel generations depending on real-time capacity. If you receive a 429 Too Many Requests or 503 Service Unavailable response, simply wait 5-10 seconds before retrying—both status codes indicate temporary capacity constraints and are safe to retry. Image generation typically completes within 10-20 seconds.

Important notes:

  • Nano Banana model: The nano-banana model is primarily designed for image editing with context references. When used with text prompts only (no reference images), it may produce unexpected results or occasionally return HTTP 500 errors. If this occurs, try switching to imagen-4 which often successfully processes prompts that were rejected by nano-banana.
  • Content moderation: If your generation is moderated, retrying with the same prompt often succeeds on subsequent attempts as moderation decisions can vary between requests. Alternatively, switching between imagen-4 and nano-banana models may help, as they have different content moderation behaviors.

Use any Google AI subscription or even free account for unlimited image generations.

Model Capabilities

Parameter Imagen 4
imagen-4 (default)
Nano Banana / Gemini 2.5 Flash Image
nano-banana
styleReference_1
contextReference_1 to _4 ✓ (max 3) ✓ (max 4)
count ✓ (1-4) ✓ (1-4)
seed

https://api.useapi.net/v1/google-flow/images

Request Headers

Authorization: Bearer {API token}
Content-Type: application/json
# Alternatively you can use multipart/form-data
# Content-Type: multipart/form-data

Request Body

{
  "prompt": "A serene mountain landscape at sunset with vibrant colors",
  "model": "imagen-4",
  "aspectRatio": "landscape",
  "count": 4,
  "seed": 123456
}
  • email is optional when only one account configured. However, if you have multiple accounts configured, this parameter becomes required. If reference images (styleReference_1 or contextReference_1 to _4) are provided, the email parameter can be omitted—the API will automatically use the same account where the images were uploaded.
  • prompt is required, text description for image generation.
  • model is optional, the AI model to use for image generation (default: imagen-4).
    Supported values: imagen-4, nano-banana.
  • aspectRatio is optional, output image aspect ratio (default: landscape).
    Supported values: landscape, portrait, square.
  • count is optional, number of image variations to generate (1-4, default: 4).
  • seed is optional, random seed for reproducible results (integer ≥ 0).
  • styleReference_1 is optional, mediaGenerationId from POST /assets/email for style influence (Imagen 4 only).
  • contextReference_1 to contextReference_4 are optional, use mediaGenerationId from POST /assets/email for context influence. Imagen 4 supports max 3 context references, Nano Banana supports max 4.

Auto-detection: If model is not specified and context references are provided, the API automatically selects nano-banana (supports 4 context refs). Otherwise defaults to imagen-4.

Responses

  • 200 OK

    Images generated successfully. Returns panels with generated image candidates.

    {
      "imagePanels": [
        {
          "prompt": "A serene mountain landscape at sunset with vibrant colors",
          "generatedImages": [
            {
              "encodedImage": "/9j/4AAQSkZJRgABAQAAAQABAAD...(base64 encoded JPEG)",
              "seed": 123456,
              "mediaGenerationId": {
                "mediaGenerationId": "user:791-email:6a6f...2e636f6d-image:CAMaJDgy..."
              },
              "prompt": "A serene mountain landscape at sunset with vibrant colors",
              "modelNameType": "IMAGEN_3_5",
              "workflowId": "workflow_abc123",
              "aspectRatio": "IMAGE_ASPECT_RATIO_LANDSCAPE",
              "requestData": {
                "promptInputs": [
                  {
                    "textInput": "A serene mountain landscape at sunset with vibrant colors"
                  }
                ],
                "imageGenerationRequestData": {
                  "imageGenerationImageInputs": []
                }
              }
            }
          ]
        }
      ]
    }
    
  • 400 Bad Request

    Invalid request (validation error, reference count exceeded, email mismatch, or content policy violation).

    General error:

    {
      "error": "Model nano-banana supports maximum 4 context references"
    }
    

    Content policy error:

    {
      "error": {
        "code": 400,
        "message": "Request contains an invalid argument.",
        "status": "INVALID_ARGUMENT",
        "details": [
          {
            "@type": "type.googleapis.com/google.rpc.ErrorInfo",
            "reason": "PUBLIC_ERROR_UNSAFE_GENERATION"
          }
        ]
      }
    }
    
  • 401 Unauthorized

    Invalid API token.

    {
      "error": "Unauthorized"
    }
    
  • 402 Payment Required

    Subscription expired or insufficient credits.

    {
      "error": "Account has no subscription or subscription expired"
    }
    
  • 403 Forbidden

    Unauthorized access to reference images from another user.

    {
      "error": "Unauthorized access to user:123 detected in reference user:123-email:...-image:..."
    }
    
  • 404 Not Found

    Account not found or not configured.

    {
      "error": "Google Flow account [email protected] not found"
    }
    
  • 429 Too Many Requests

    Concurrency limit reached. Wait 5-10 seconds and retry.

    {
      "error": {
        "code": 429,
        "message": "Resource has been exhausted (e.g. check quota).",
        "status": "RESOURCE_EXHAUSTED",
        "details": [
          {
            "@type": "type.googleapis.com/google.rpc.ErrorInfo",
            "reason": "PUBLIC_ERROR_USER_REQUESTS_THROTTLED"
          }
        ]
      }
    }
    
  • 500 Internal Server Error

    One or more generated images were moderated by Google’s content policy. Try one of the following:

    • Switch to imagen-4 model (often successfully processes prompts rejected by nano-banana)
    • Modify your prompt or remove/change reference images
    • Retry the same request (moderation decisions can vary between attempts)
    {
      "error": {
        "code": 500,
        "message": "Internal error encountered.",
        "status": "INTERNAL"
      }
    }
    
  • 503 Service Unavailable

    Service temporarily unavailable. Wait 5-10 seconds and retry.

    {
      "error": {
        "code": 503,
        "message": "Service temporarily unavailable.",
        "status": "UNAVAILABLE",
        "details": [
          {
            "@type": "type.googleapis.com/google.rpc.ErrorInfo",
            "reason": "SERVICE_UNAVAILABLE"
          }
        ]
      }
    }
    
  • 596 Session Error

    Google session refresh failed. The account cookies needs to be updated following the instructions in Setup Google Flow.

    {
      "error": "Failed to refresh session."
    }
    

Model

  • imagePanels - Array of generated image panels (typically one panel per prompt)
  • imagePanels[].prompt - The prompt used for generation
  • imagePanels[].generatedImages - Array of generated image candidates (1-4 images based on count)
  • generatedImages[].encodedImage - Base64-encoded JPEG image data
  • generatedImages[].seed - Seed used for this generation (for reproducibility)
  • generatedImages[].mediaGenerationId.mediaGenerationId - mediaGenerationId for use in subsequent API calls
  • generatedImages[].modelNameType - Model variant used (IMAGEN_3_5, R2I, GEM_PIX)
  • generatedImages[].aspectRatio - Generated image aspect ratio
{
  imagePanels: Array<{
    prompt: string
    generatedImages: Array<{
      encodedImage: string          // Base64-encoded JPEG
      seed: number
      mediaGenerationId: {
        mediaGenerationId: string   // Format: user:{userid}-email:{hex}-image:{id}
      }
      prompt: string
      modelNameType: string         // IMAGEN_3_5 | R2I | GEM_PIX
      workflowId: string
      fingerprintLogRecordId?: string
      aspectRatio: string           // IMAGE_ASPECT_RATIO_LANDSCAPE | PORTRAIT | SQUARE
      requestData: {
        promptInputs: Array<{
          textInput: string
        }>
        imageGenerationRequestData: {
          imageGenerationImageInputs?: Array<{
            mediaGenerationId: string
          }>
        }
      }
    }>
  }>
  error?: string | {                // Error: string (useapi.net) or object (Google API)
    code: number
    message: string
    status: string
    details: Array<{
      '@type': string
      reason: string
    }>
  }
}

Examples

  • curl -X POST \
         -H "Authorization: Bearer YOUR_API_TOKEN" \
         -H "Content-Type: application/json" \
         -d '{
           "prompt": "A serene mountain landscape at sunset with vibrant colors",
           "model": "imagen-4",
           "aspectRatio": "landscape",
           "count": 4,
           "seed": 123456
         }' \
         "https://api.useapi.net/v1/google-flow/images" > response.json
    
    # Extract and decode images using jq and base64
    cat response.json | jq -r '.imagePanels[0].generatedImages[0].encodedImage' | base64 -d > image_1.jpg
    cat response.json | jq -r '.imagePanels[0].generatedImages[1].encodedImage' | base64 -d > image_2.jpg
    # Continue for remaining images...
    
  • const token = 'YOUR_API_TOKEN';
    const apiUrl = 'https://api.useapi.net/v1/google-flow/images';
    
    const response = await fetch(apiUrl, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        prompt: 'A serene mountain landscape at sunset with vibrant colors',
        model: 'imagen-4',
        aspectRatio: 'landscape',
        count: 4,
        seed: 123456
      })
    });
    
    const result = await response.json();
    console.log('Generated images:', result.imagePanels[0].generatedImages.length);
    
    // Save images from base64
    result.imagePanels[0].generatedImages.forEach((img, index) => {
      console.log(`Image ${index + 1} seed:`, img.seed);
      console.log(`mediaGenerationId:`, img.mediaGenerationId.mediaGenerationId);
    
      // Decode base64 to binary
      const binaryString = atob(img.encodedImage);
      const bytes = new Uint8Array(binaryString.length);
      for (let i = 0; i < binaryString.length; i++) {
        bytes[i] = binaryString.charCodeAt(i);
      }
    
      // Create blob and save (Node.js)
      const blob = new Blob([bytes], { type: 'image/jpeg' });
      // In Node.js: require('fs').writeFileSync(`generated_image_${index + 1}.jpg`, Buffer.from(bytes));
      // In browser: can create download link or display in <img> element
    });
    
  • import requests
    import base64
    
    token = 'YOUR_API_TOKEN'
    api_url = 'https://api.useapi.net/v1/google-flow/images'
    
    headers = {
        'Authorization': f'Bearer {token}',
        'Content-Type': 'application/json'
    }
    
    data = {
        'prompt': 'A serene mountain landscape at sunset with vibrant colors',
        'model': 'imagen-4',
        'aspectRatio': 'landscape',
        'count': 4,
        'seed': 123456
    }
    
    response = requests.post(api_url, headers=headers, json=data)
    result = response.json()
    
    print(f"Generated {len(result['imagePanels'][0]['generatedImages'])} images")
    
    # Save images from base64
    for index, img in enumerate(result['imagePanels'][0]['generatedImages']):
        print(f"Image {index + 1} seed:", img['seed'])
        print(f"mediaGenerationId:", img['mediaGenerationId']['mediaGenerationId'])
    
        # Decode and save image
        image_data = base64.b64decode(img['encodedImage'])
        with open(f'generated_image_{index + 1}.jpg', 'wb') as f:
            f.write(image_data)
    

Try It