Doc says yes supported @https://ai.google.dev/gemini-api/docs/models#gemini-2.5-flash-image
but when making api call, it throws `400 error: JSON mode is not enabled for this model`
Doc says yes supported @https://ai.google.dev/gemini-api/docs/models#gemini-2.5-flash-image
but when making api call, it throws `400 error: JSON mode is not enabled for this model`
Hii @wenhui_luo
Welcome to the AI Forum!!!
Yes, The Gemini-2.5-flash-image supports structured output. Could you please share the full payload details along with some sample of the code which you are using? We would like to reproduce the issue.
In the meantime, could you try running it with the Gemini-2.5 model? If you still encounter the problem, please let me know.
@Shivam_Singh2 thx for the reply!
Below is a 400 error example (using prompt and json schema in https://ai.google.dev/gemini-api/docs/structured-output#rest):
curl --location 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent?key=<GEMINI_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"contents": [
{
"parts": [
{ "text": "List a few popular cookie recipes, and include the amounts of ingredients, then create an image of them." }
]
}
],
"generationConfig": {
"responseMimeType": "application/json",
"responseSchema": {
"type": "ARRAY",
"items": {
"type": "OBJECT",
"properties": {
"recipeName": { "type": "STRING" },
"ingredients": {
"type": "ARRAY",
"items": { "type": "STRING" }
}
},
"propertyOrdering": ["recipeName", "ingredients"]
}
}
}
}'
response 400:
{
"error": {
"code": 400,
"message": "JSON mode is not enabled for this model",
"status": "INVALID_ARGUMENT"
}
}
Change model from “gemini-2.5-flash-image“ to “gemini-2.5-flash“ and keep everything else the same:
curl --location 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=<GEMINI_API_KEY>' \
--header 'Content-Type: application/json' \
--data '{
"contents": [
{
"parts": [
{ "text": "List a few popular cookie recipes, and include the amounts of ingredients, then create an image of them." }
]
}
],
"generationConfig": {
"responseMimeType": "application/json",
"responseSchema": {
"type": "ARRAY",
"items": {
"type": "OBJECT",
"properties": {
"recipeName": { "type": "STRING" },
"ingredients": {
"type": "ARRAY",
"items": { "type": "STRING" }
}
},
"propertyOrdering": ["recipeName", "ingredients"]
}
}
}
}'
response 200:
{
"candidates": [
{
"content": {
"parts": [
{
"text": "[{\"recipeName\":\"Chocolate Chip Cookies\",\"ingredients\":[\"1 cup (2 sticks) unsalted butter, softened\",\"3/4 cup granulated sugar\",\"3/4 cup packed light brown sugar\",\"2 large eggs\",\"1 teaspoon vanilla extract\",\"2 1/4 cups all-purpose flour\",\"1 teaspoon baking soda\",\"1/2 teaspoon salt\",\"2 cups (12 oz) chocolate chips\"]}, {\"recipeName\":\"Sugar Cookies\",\"ingredients\":[\"1 cup (2 sticks) unsalted butter, softened\",\"1 1/2 cups granulated sugar\",\"1 large egg\",\"1 teaspoon vanilla extract\",\"2 3/4 cups all-purpose flour\",\"1 teaspoon baking powder\",\"1/2 teaspoon salt\"]}, {\"recipeName\":\"Oatmeal Raisin Cookies\",\"ingredients\":[\"1 cup (2 sticks) unsalted butter, softened\",\"1 cup packed light brown sugar\",\"1/2 cup granulated sugar\",\"2 large eggs\",\"1 teaspoon vanilla extract\",\"1 1/2 cups all-purpose flour\",\"1 teaspoon baking soda\",\"1 teaspoon ground cinnamon\",\"1/2 teaspoon salt\",\"3 cups old-fashioned rolled oats\",\"1 cup raisins\"]}]"
}
],
"role": "model"
},
"finishReason": "STOP",
"index": 0
}
],
"usageMetadata": {
"promptTokenCount": 21,
"candidatesTokenCount": 229,
"totalTokenCount": 784,
"promptTokensDetails": [
{
"modality": "TEXT",
"tokenCount": 21
}
],
"thoughtsTokenCount": 534
},
"modelVersion": "gemini-2.5-flash",
"responseId": "MSgKae3rG_Hhz7IPosfrqQ8"
}
@Shivam_Singh2 is this the end of the conversation?