POST
/
v1beta
/
models
/
{model}
:generateContent
curl -X POST "https://api.example.com/v1beta/models/gemini-2.5-pro:generateContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "List 3 popular programming languages with their use cases"
          }
        ]
      }
    ],
    "generationConfig": {
      "temperature": 0.7,
      "responseMimeType": "application/json",
      "responseSchema": {
        "type": "object",
        "properties": {
          "languages": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "useCase": {
                  "type": "string"
                }
              },
              "required": ["name", "useCase"]
            }
          }
        },
        "required": ["languages"]
      }
    }
  }'
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "{\"languages\":[{\"name\":\"Python\",\"useCase\":\"Data science, web development, automation\"},{\"name\":\"JavaScript\",\"useCase\":\"Web development, frontend and backend\"},{\"name\":\"Java\",\"useCase\":\"Enterprise applications, Android development\"}]}"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ]
}
Official documentation: https://ai.google.dev/gemini-api/docs/structured-output
Generate structured, schema-compliant JSON output using Google Gemini models. This feature ensures the model’s response follows a specific JSON schema you define.

Request Parameters

key
string
required
API key.
contents
array
required
Content array.Each content object contains:
  • role (string): Role (user or model)
  • parts (array): Content parts array
generationConfig
object
Generation configuration.
  • temperature (number): Sampling temperature
  • topP (number): Nucleus sampling parameter
  • responseMimeType (string): Set to “application/json” for JSON output
  • responseSchema (object): JSON schema defining the expected output structure

Response

Returns structured JSON output conforming to the specified schema.
curl -X POST "https://api.example.com/v1beta/models/gemini-2.5-pro:generateContent?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "List 3 popular programming languages with their use cases"
          }
        ]
      }
    ],
    "generationConfig": {
      "temperature": 0.7,
      "responseMimeType": "application/json",
      "responseSchema": {
        "type": "object",
        "properties": {
          "languages": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "string"
                },
                "useCase": {
                  "type": "string"
                }
              },
              "required": ["name", "useCase"]
            }
          }
        },
        "required": ["languages"]
      }
    }
  }'
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "{\"languages\":[{\"name\":\"Python\",\"useCase\":\"Data science, web development, automation\"},{\"name\":\"JavaScript\",\"useCase\":\"Web development, frontend and backend\"},{\"name\":\"Java\",\"useCase\":\"Enterprise applications, Android development\"}]}"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ]
}