Skip to main content
POST
/
v1
/
models
/
{model}
:generateContent
Generate content (Gemini)
curl --request POST \
  --url https://api.dgrid.ai/v1/models/{model}:generateContent \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Hello from DGrid."
        }
      ]
    }
  ]
}
'
{
  "candidates": [
    {
      "content": {
        "role": "<string>",
        "parts": [
          {}
        ]
      },
      "finishReason": "<string>",
      "safetyRatings": [
        {}
      ]
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 123,
    "candidatesTokenCount": 123,
    "totalTokenCount": 123
  }
}
This page uses the same generateContent operation as Generate content (Gemini), with the playground above pre-filled for plain text chat. The notes below describe the Gemini-native fields you can add to generationConfig to generate or edit images with provider-specific response controls.
Set generationConfig.responseModalities to ["IMAGE"] to request image output, and use generationConfig.imageConfig to control the aspect ratio and output size.

Gemini-native request fields

FieldTypeRequiredDescription
generationConfig.responseModalitiesarrayYesRequested modalities array, e.g. ["IMAGE"].
generationConfig.imageConfigobjectNoImage configuration object.
generationConfig.imageConfig.aspectRatiostringNoAspect ratio for the generated image, e.g. 1:1.
generationConfig.imageConfig.imageSizestringNoOutput image size, e.g. 1024x1024.
Use an image-generation-capable model such as gemini-2.0-flash-preview-image-generation in the model path parameter.

Example: generating an image

{
  "contents": [
    {
      "role": "user",
      "parts": [
        { "text": "A photorealistic image of a corgi wearing sunglasses on a beach." }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": ["IMAGE"],
    "imageConfig": {
      "aspectRatio": "1:1",
      "imageSize": "1024x1024"
    }
  }
}

Response fields

The response follows the standard generateContent shape. When image output is requested, the returned parts contain inline image data:
candidates
array
Candidate responses returned by the model.
usageMetadata
object
Token usage metadata, including promptTokenCount, candidatesTokenCount, and totalTokenCount.

Example response

200
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "<base64-encoded-image-bytes>"
            }
          }
        ]
      },
      "finishReason": "STOP",
      "safetyRatings": []
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 14,
    "candidatesTokenCount": 0,
    "totalTokenCount": 14
  }
}

Authorizations

Authorization
string
header
required

Your DGrid API key. All endpoints use Authorization: Bearer <DGRID_API_KEY>.

Path Parameters

model
string
required

Target model ID, such as gemini-1.5-pro.

Body

application/json
contents
object[]

Input content array with role and parts.

generationConfig
object

Generation configuration.

Response

Generated content candidates.

candidates
object[]

Candidate responses returned by the model.

usageMetadata
object

Token accounting metadata.