Days of 503 overloaded or 504 etc on images, YouTube lookups

Hello everyone,

Paid tier 1, project in Cloud, billing set up, etc.

It’s not usable like this, even for me to build something, never mind a product for a client. The exception this week appears to be that it works, but when seems to be completely random.

Simplest test prompt possible for one basic image. Run it through 3 models. gemini-3-pro-image-preview and nano-banana-pro-preview, the ones we would actually like to use for the project, of course, are just returning 504 or 503 errors.

How can Google have overload problems for a few api images? It’s Google.

Any help appreciated. [EDIT: happy to use Vertex or whatever if there are actually live working api versions of the top models somewhere else I am unaware of]

import sys
import os
import time
import traceback
from google.genai import types
from google.genai import errors

# Ensure global root is in Python path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..')))

from common.apis.gemini.api_gemini import client

MODELS_TO_TEST = [
    "gemini-2.5-flash-image",
    "gemini-3-pro-image-preview",
    "nano-banana-pro-preview"
]

def test_simple_image_gen():
    print(f"🧪 Testing Basic Image Generation...")
    
    prompt = "A cute robot artist painting a canvas, high quality, 3d render style."

    for model_name in MODELS_TO_TEST:
        print("\n" + "="*50)
        print(f"📸 Testing Model: {model_name}")
        print("="*50)

        safe_model_name = model_name.replace("-", "_").replace(".", "_")
        filename = f"test_image_hello_world_{safe_model_name}.png"
        output_file = os.path.join(os.path.dirname(__file__), filename)

        print(f"📝 Prompt: {prompt}")
        print("⏳ Sending request...")
        start_time = time.time()

        try:
            print(f"   ▶️ HttpOptions: timeout=60s")
            response = client.models.generate_content(
                model=model_name,
                contents=prompt,
                config=types.GenerateContentConfig(
                    response_modalities=['Image'],
                    image_config=types.ImageConfig(
                        aspect_ratio="9:16", 
                    ),
                    http_options=types.HttpOptions(timeout=60000) # 60 seconds
                )
            )

            elapsed = time.time() - start_time
            print(f"✅ SUCCESS! Response received in {elapsed:.2f} seconds.")

            if response.parts:
                for part in response.parts:
                    if part.inline_data:
                        with open(output_file, "wb") as f:
                            f.write(part.inline_data.data)
                        print(f"🖼️ Saved image to {output_file}")
                        break
                else:
                     print("⚠️ No image data found in response parts.")
            else:
                 print("⚠️ No response parts.")

        except errors.ClientError as e:
            print(f"❌ CLIENT ERROR: {e}")
            if hasattr(e, 'message'):
                print(f"   Message: {e.message}")
            if hasattr(e, 'code'):
                print(f"   Code: {e.code}")
            if hasattr(e, 'status'):
                 print(f"   Status: {e.status}")
                 
        except errors.ServerError as e:
            print(f"❌ SERVER ERROR: {e}")
            if hasattr(e, 'message'):
                 print(f"   Message: {e.message}")
            
        except Exception as e:
            print(f"❌ UNEXPECTED ERROR: {type(e).__name__}: {e}")
            traceback.print_exc()

if __name__ == "__main__":
    test_simple_image_gen()