Hi everyone, I am getting a cors error
Hi everyone, I am getting a cors error while trying to call this cloud function that uses the imagen 3 api. I tried adding cors: true in onCallGenkit, that did not help
and we use httpcallable to call this from client.
const apiKey = defineSecret("GOOGLE_GENAI_API_KEY");
const ai = genkit({
plugins: [
vertexAI({ location: "us-central1" })
]
});
const productImageFlow = ai.defineFlow(
{
name: "productImageEditor",
},
async ({ baseImage, description }) => {
try {
const response = await ai.generate({
model: imagen3,
output: { format: "media" },
prompt: [
{
media: {
url: baseImage.startsWith("data:") ? baseImage : `data:image/png;base64,${baseImage}`
}
},
{ text: description }
],
config: {
editConfig: {
editMode: "product-image",
enhanceDetails: true,
backgroundReplacement: "studio"
}
}
});
return response.media();
} catch (error) {
throw new Error(`Image generation failed: ${error.message}`);
}
}
);
exports.generateProductPhoto = onCallGenkit(
{
secrets: [apiKey],
authPolicy: hasClaim("email_verified"),
},
productImageFlow); const apiKey = defineSecret("GOOGLE_GENAI_API_KEY");
const ai = genkit({
plugins: [
vertexAI({ location: "us-central1" })
]
});
const productImageFlow = ai.defineFlow(
{
name: "productImageEditor",
},
async ({ baseImage, description }) => {
try {
const response = await ai.generate({
model: imagen3,
output: { format: "media" },
prompt: [
{
media: {
url: baseImage.startsWith("data:") ? baseImage : `data:image/png;base64,${baseImage}`
}
},
{ text: description }
],
config: {
editConfig: {
editMode: "product-image",
enhanceDetails: true,
backgroundReplacement: "studio"
}
}
});
return response.media();
} catch (error) {
throw new Error(`Image generation failed: ${error.message}`);
}
}
);
exports.generateProductPhoto = onCallGenkit(
{
secrets: [apiKey],
authPolicy: hasClaim("email_verified"),
},
productImageFlow); and we use httpcallable to call this from client.
const editor = httpsCallable(functions, 'generateProductPhoto');
const result = await editor({
baseImage: file,
description: description
}); const editor = httpsCallable(functions, 'generateProductPhoto');
const result = await editor({
baseImage: file,
description: description
});