I'm facing the same issue. How can I use the Gemini API for image generation?
Your URL request is incorrect; you forgot to include __:generateContent__
/v1beta/models/gemini-2.0-flash-preview-image-generation:generateContent__
Good catch. Still erroring though. [404] models/gemini-2.0-flash-preview-image-generation is not found for API version v1beta, or is not supported for generateContent. Call ListModels to see the list of available models and their supported methods.
As per the documentation found at Image generation | Gemini API | Google AI for Developers, the supported versions for image generation are:
- For Gemini, utilize Gemini 2.0 Flash Preview Image Generation.
- For Imagen, use Imagen 3. Please note that this model is exclusively available on the Paid tier.
This configuration has worked for me.
Could your API key be restricted from generating images?
Replace "GEMINIAPIKEY" with your actual ApiKey and test it.
You can copy the curl code from here: https://aistudio.google.com/app/apikey
As an alternative, you could use the Google Vertex AI (Gemini) app.
This includes a specific module for Generate an Image, with Gemini 2.0 Flash and Imagen 3 models available.
It utilizes a slightly different underlying Google API. Authentication is handled via OAuth (username and password) instead of an API Key, thus offering enhanced security.