> ## Documentation Index
> Fetch the complete documentation index at: https://docs-vip.apigo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Gemini structured output example

> Structured output example for Gemini.

## Recommended endpoint

* [Gemini /v1beta/models/{model}:generateContent](/en/api-reference/endpoints/gemini/text)

## Minimal request

```json theme={null}
{
  "model": "gemini-2.5-flash",
  "contents": [
    {
      "role": "user",
      "parts": [{ "text": "Extract order fields and return JSON." }]
    }
  ],
  "generationConfig": {
    "responseMimeType": "application/json"
  }
}
```

## cURL example

```bash theme={null}
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [{ "text": "Extract order fields and return JSON." }]
      }
    ],
    "generationConfig": {
      "responseMimeType": "application/json"
    }
  }'
```

## Python example

```python theme={null}
import requests

response = requests.post(
    "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",
    headers={
        "x-goog-api-key": "<GEMINI_API_KEY>",
        "Content-Type": "application/json",
    },
    json={
        "contents": [
            {
                "role": "user",
                "parts": [{"text": "Extract order fields and return JSON."}],
            }
        ],
        "generationConfig": {
            "responseMimeType": "application/json",
        },
    },
)

print(response.json())
```

## Node.js example

```js theme={null}
const response = await fetch(
  "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent",
  {
    method: "POST",
    headers: {
      "x-goog-api-key": process.env.GEMINI_API_KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      contents: [
        {
          role: "user",
          parts: [{ text: "Extract order fields and return JSON." }]
        }
      ],
      generationConfig: {
        responseMimeType: "application/json"
      }
    }),
  }
);

console.log(await response.json());
```

## Best practices

* Set `responseMimeType` explicitly for structured output
* Put the expected field shape into the prompt when output requirements are strict
* Parse and validate JSON on the server before exposing it downstream
