Skip to content

API doc states model: gemini-2.5-flash-image supports Structured Output, but it doesn't. #1028

@FisherWL

Description

@FisherWL

Description of the bug:

In official doc (https://ai.google.dev/gemini-api/docs/models#gemini-2.5-flash-image) it says Structured Output supported:
Image

But when making requests, it returns 400 "JSON mode is not enabled for this model".

Actual vs expected behavior:

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"
    }
}

If change model from gemini-2.5-flash-image to gemini-2.5-flash while keeping everything else the same, the response becomes OK:

{
    "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"
}

Any other information you'd like to share?

removing "responseMimeType": "application/json",, doesn't work;
adding "responseModalities": ["Image", "Text"],, doesn't work;
using _responseJsonSchema , doesn't work.

Metadata

Metadata

Assignees

Labels

Component:image generationIssues/PRs related to examples of image generation models.type:bugSomething isn't workingtype:documentationThe documentation needs to be updated

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions