Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Quota limit with imagen Error code 429 despite unused quota

I'm trying to generate images using the imagen-3.0-generate-002 model by running a python script in my github workflow and I'm encountering the following error:
Error generating image: 429 Quota exceeded for aiplatform.googleapis.com/generate_content_requests_per_minute_per_project_per_base_model with base model: imagen-3.0-generate. Please submit a quota increase request. https://cloud.google.com/vertex-ai/docs/generative-ai/quotas-genai.

Screenshot 2025-02-08 at 8.44.52 PM.png

I'm able to make normal text requests to vertex ai without issues. I've even tried to request image generation in isolation so as to not hit rate limits. My project quota indicates a value of 10 with none used. I also have billing enabled. Why am I still getting the error? My request code is below:

 

import os
import json
import base64
from datetime import datetime
from pathlib import Path
from google.cloud import aiplatform
from vertexai.preview.generative_models import GenerativeModel
import vertexai

def generate_single_image():
    """Generate a single AI image for testing"""
    try:
        print("\n🎨 Initializing AI image generation...")
        
        # Initialize Vertex AI
        project_id = os.getenv('GCP_PROJECT_ID')
        location = os.getenv('GCP_LOCATION')
        vertexai.init(project=project_id, location=location)
        
        image_model = GenerativeModel("imagen-3.0-generate-002")
                
        prompt = f"""
        An apple riding a motorcycle
        """
                
        response = image_model.generate_content(
            prompt,
            generation_config={
                "temperature": 0.8,
            }
        )
        
        image_bytes = response.candidates[0].content.parts[0]
        image_base64 = base64.b64encode(image_bytes).decode('utf-8')
        
        return image_base64
            
    except Exception as e:
        print(f"\n Error generating image: {str(e)}")
        raise e

def main():
    try:
        print("Starting image generation...")
        
        image_data = generate_single_image()

    except Exception as e:
        print(f"\n Error: {str(e)}")
        raise e

if __name__ == "__main__":
    main()

 

 

0 2 573
2 REPLIES 2

Hi @anupdsouza,

Welcome to Google Cloud Community!

It looks like you are encountering a "429 Quota exceeded" error when generating images using the Vertex AI Imagen model. Despite having an underutilized quota (0% usage with a limit of 10 requests per minute), text requests work fine, but image generation fails. You have ensured billing is enabled, and your rate limits should be sufficient.

Here are the potential ways that might help with your use case:

  • Incorrect Quota Inspection: Ensure that your quota wording and base model are correct. Confirm your region in your code, and verify your Google Cloud project ID. Be aware that your GitHub workflow service account might have different permissions or quotas, and ensure you have no concurrent requests as rate limits are strictly calculated.
  • Quota Propagation Delay: If you recently increased your quota, changes may take time to propagate. The "Values for Compute Engine API... being updated" message suggests your changes are in progress and could take up to two weeks. Wait 24-48 hours and try again. Also, ensure your project is linked to an active billing account, as billing issues can cause your API calls to fail due to quota errors.
  • Retry with Exponential Backoff: You should add a retry mechanism with exponential backoff in your code. When your API call fails with a 429 error, wait briefly, then retry. If it fails again, wait a bit longer, and continue this way. This prevents your code from overloading the API if it’s temporarily busy.
  • Limited Retries: You may want to limit retries to prevent your code from getting stuck in an infinite loop.
  • Error Handling: You may want to implement error handling using a try-except block to manage potential errors during image generation.

For more detailed information, you can refer to the following documentation on Google Cloud's quotas and billing:

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.

 

I'm also encountering this issue. Interestingly, if I generate the image using Vertex AI Studio, the quota is utilized. But when I'm using API, it's underutilized and I'm encountering 429 error.