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

# Format Gemini natif

> Gemini-native generateContent interface for text chat, multimodal media recognition (images, audio, video), speech synthesis, and image generation with structured parts. Use `generationConfig` to request specific response modalities such as speech (`speechConfig`) or images (`imageConfig`).

Cette page utilise la même opération `generateContent` que [Générer du contenu (Gemini)](/fr/api-reference/chat/generate-content), avec le playground ci-dessus prérempli pour un chat en texte brut. Les notes ci-dessous décrivent les champs natifs Gemini que vous pouvez ajouter à `generationConfig` pour générer ou modifier des images avec des contrôles de réponse spécifiques au fournisseur.

<Note>
  Définissez `generationConfig.responseModalities` sur `["IMAGE"]` pour demander une sortie image, puis utilisez `generationConfig.imageConfig` pour contrôler le ratio d'aspect et la taille de sortie.
</Note>

### Champs de requête natifs Gemini

| Champ                                      | Type   | Requis | Description                                               |
| ------------------------------------------ | ------ | ------ | --------------------------------------------------------- |
| `generationConfig.responseModalities`      | array  | Oui    | Tableau des modalités demandées, par exemple `["IMAGE"]`. |
| `generationConfig.imageConfig`             | object | Non    | Objet de configuration d'image.                           |
| `generationConfig.imageConfig.aspectRatio` | string | Non    | Ratio d'aspect de l'image générée, par exemple `1:1`.     |
| `generationConfig.imageConfig.imageSize`   | string | Non    | Taille de sortie de l'image, par exemple `1024x1024`.     |

<Tip>
  Utilisez un modèle capable de génération d'images tel que `gemini-2.0-flash-preview-image-generation` dans le paramètre de chemin `model`.
</Tip>

### Exemple : générer une image

```json theme={null}
{
  "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"
    }
  }
}
```

### Champs de réponse

La réponse suit la forme standard `generateContent`. Lorsqu'une sortie image est demandée, les `parts` renvoyés contiennent des données image inline :

<ResponseField name="candidates" type="array">
  Réponses candidates renvoyées par le modèle.

  <Expandable title="candidate properties">
    <ResponseField name="content" type="object">
      Objet de contenu généré.

      <Expandable title="content properties">
        <ResponseField name="role" type="string">
          Rôle renvoyé dans le bloc de contenu généré, généralement `model`.
        </ResponseField>

        <ResponseField name="parts" type="array">
          Parts de contenu renvoyées. Pour une sortie image, chaque part contient un objet `inlineData` avec `mimeType` (par exemple `image/png`) et `data` encodé en base64.
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="finishReason" type="string">
      Chaîne indiquant la raison de fin, par exemple `STOP`.
    </ResponseField>

    <ResponseField name="safetyRatings" type="array">
      Résultats d'évaluation de sécurité.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="usageMetadata" type="object">
  Métadonnées d'utilisation des tokens, notamment `promptTokenCount`, `candidatesTokenCount` et `totalTokenCount`.
</ResponseField>

### Exemple de réponse

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


## OpenAPI

````yaml api-reference/openapi.json POST /v1/models/{model}:generateContent
openapi: 3.1.0
info:
  title: DGrid AI Gateway API
  description: >-
    A single, unified API to access 200+ leading AI models. OpenAI-, Claude-,
    and Gemini-compatible endpoints for chat, completions, embeddings, images,
    audio, and moderations.
  version: 1.0.0
  contact:
    name: DGrid AI
    url: https://dgrid.ai
servers:
  - url: https://api.dgrid.ai
    description: DGrid AI Gateway
security:
  - bearerAuth: []
paths:
  /v1/models/{model}:generateContent:
    post:
      tags:
        - Chat
      summary: Generate content (Gemini)
      description: >-
        Gemini-native generateContent interface for text chat, multimodal media
        recognition (images, audio, video), speech synthesis, and image
        generation with structured parts. Use `generationConfig` to request
        specific response modalities such as speech (`speechConfig`) or images
        (`imageConfig`).
      operationId: generateContent
      parameters:
        - name: model
          in: path
          required: true
          schema:
            type: string
          description: Target model ID, such as `gemini-1.5-pro`.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                contents:
                  type: array
                  description: Input content array with role and parts.
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        description: Content role.
                      parts:
                        type: array
                        description: Content parts (text, inline data, media).
                        items:
                          type: object
                generationConfig:
                  type: object
                  description: Generation configuration.
                  properties:
                    responseModalities:
                      type: array
                      items:
                        type: string
                      description: >-
                        Requested response modalities, such as `TEXT`, `AUDIO`,
                        or `IMAGE`.
                    speechConfig:
                      type: object
                      description: Speech configuration for audio output.
                      properties:
                        voiceConfig:
                          type: object
                          properties:
                            prebuiltVoiceConfig:
                              type: object
                              properties:
                                voiceName:
                                  type: string
                                  description: Voice preset name.
                    imageConfig:
                      type: object
                      description: Image configuration for image output.
                      properties:
                        aspectRatio:
                          type: string
                          description: Aspect ratio.
                        imageSize:
                          type: string
                          description: Image size.
            example:
              contents:
                - role: user
                  parts:
                    - text: Hello from DGrid.
      responses:
        '200':
          description: Generated content candidates.
          content:
            application/json:
              schema:
                type: object
                properties:
                  candidates:
                    type: array
                    description: Candidate responses returned by the model.
                    items:
                      type: object
                      properties:
                        content:
                          type: object
                          description: Generated content object.
                          properties:
                            role:
                              type: string
                              description: Role in the generated content block.
                            parts:
                              type: array
                              description: Returned content parts.
                              items:
                                type: object
                        finishReason:
                          type: string
                          description: Finish reason string.
                        safetyRatings:
                          type: array
                          description: Safety evaluation results.
                          items:
                            type: object
                  usageMetadata:
                    type: object
                    description: Token accounting metadata.
                    properties:
                      promptTokenCount:
                        type: integer
                      candidatesTokenCount:
                        type: integer
                      totalTokenCount:
                        type: integer
        '400':
          $ref: '#/components/responses/BadRequest'
components:
  responses:
    BadRequest:
      description: Invalid request.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            param:
              type: string
            code:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Your DGrid API key. All endpoints use `Authorization: Bearer
        <DGRID_API_KEY>`.

````