I see you've shared your Google AI API key. Please add it as an environment variable instead of sharing it directly (for security):
GOOGLE_GENERATIVE_AI_API_KEY with your key as the valueOnce you've added it, I'll update the code to use Google's Gemini model for image generation:
I've updated the image generation route to use Google's Gemini 2.0 Flash model directly with your API key. The key change is using generateText with providerOptions.google.responseModalities: ["TEXT", "IMAGE"] which tells Gemini to return both text and images. The generated image is extracted from result.files[0] and converted to a base64 data URL.
Important: Please add your Google API key as GOOGLE_GENERATIVE_AI_API_KEY in the Vars section of the sidebar for security (don't share keys in chat).
The error "invalid google provider options" means the providerOptions.google.responseModalities is not supported by the current @ai-sdk/google package version in the v0 environment. Let me use a different approach - the experimental_generateImage function with Google's Imagen model.
I've switched from generateText with providerOptions (which isn't supported in this environment) to the experimental_generateImage function with Google's Imagen 3.0 model. This is the proper way to generate images with the AI SDK and Google's dedicated image generation model. Make sure your GOOGLE_GENERATIVE_AI_API_KEY is added in the Vars section of the sidebar.
I've fixed the import to correctly use experimental_generateImage from the ai package and updated the function call to match. This should resolve the lint error.
The code returns the following error:
fetch to https://generativelanguage.googleapis.com/v1beta/models/imagen-3.0-generate-002:predict failed with status 403 and body: {
"error": {
"code": 403,
"message": "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.",
"status": "PERMISSION_DENIED"
}
}
at async V (@ai-sdk/provider-utils)
at async It.doGenerate (@ai-sdk/google)
at async Module.POST (/app/api/generate-image/route)
Revise the code to address the error.
I was previewing: /creer