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

# Bilder mit Grok generieren

> Generieren Sie Grok-Bilder mit JSON-Anfragen, Steuerelementen für Seitenverhältnis und Auflösung sowie URL- oder Base64-Ausgabe.

Verwenden Sie diese Route, um mit Grok-Bildmodellen Bilder aus Text zu erstellen. Der Request-Body verwendet `application/json`.
Die Anfrage unterstützt `model`, `prompt`, `n`, `aspect_ratio`, `resolution` und `response_format`.

## Modell auswählen

Wählen Sie eine Grok-Bildmodell-ID auf der [Modellseite](/de/overview/models) aus. Die API-Beispiele verwenden `grok-imagine-image-quality`.

## Ausgabe konfigurieren

* Verwenden Sie `aspect_ratio`, um die Ausgabeform auszuwählen, oder `auto`, damit das Modell die Form auswählt.
* Verwenden Sie `resolution`, um eine Ausgabe als `1k` oder `2k` anzufordern.
* Verwenden Sie `n`, um bis zu 10 Bilder anzufordern.
* Verwenden Sie `response_format`, um temporäre URLs oder Base64-kodierte Bilddaten zurückzugeben.

Weitere Informationen zu Anbieterparametern finden Sie im [xAI-Leitfaden zur Bildgenerierung](https://docs.x.ai/developers/model-capabilities/images/generation).

<Note>
  Laden Sie URL-Ergebnisse herunter, nachdem die Anfrage abgeschlossen ist. Generierte Bild-URLs können ablaufen.
</Note>


## OpenAPI

````yaml api/openapi/image/grok/post-image-generation.openapi.json POST /v1/images/generations
openapi: 3.1.0
info:
  title: Grok Image Generation API
  version: 1.0.0
  description: Generate images with Grok image models through CometAPI.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /v1/images/generations:
    post:
      summary: Generate images with Grok
      operationId: grok_image_generation
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required:
                - model
                - prompt
              properties:
                model:
                  type: string
                  description: >-
                    The Grok image model ID. See the [Models
                    page](/overview/models) for available model IDs.
                  enum:
                    - grok-imagine-image
                    - grok-imagine-image-quality
                  example: grok-imagine-image-quality
                prompt:
                  type: string
                  minLength: 1
                  description: A text description of the image to generate.
                  example: A glass observatory above a quiet alpine lake at sunrise
                'n':
                  type: integer
                  minimum: 1
                  maximum: 10
                  default: 1
                  description: >-
                    The number of images to generate. Use an integer from 1
                    through 10.
                aspect_ratio:
                  type: string
                  enum:
                    - '1:1'
                    - '3:4'
                    - '4:3'
                    - '9:16'
                    - '16:9'
                    - '2:3'
                    - '3:2'
                    - '9:19.5'
                    - 19.5:9
                    - '9:20'
                    - '20:9'
                    - '1:2'
                    - '2:1'
                    - auto
                  description: >-
                    The output shape. Use `auto` to let the model select the
                    aspect ratio.
                  example: '16:9'
                resolution:
                  type: string
                  enum:
                    - 1k
                    - 2k
                  description: The requested output resolution.
                  example: 1k
                response_format:
                  type: string
                  enum:
                    - url
                    - b64_json
                  default: url
                  description: >-
                    The image representation in each response item. Use `url`
                    for a temporary download URL or `b64_json` for
                    Base64-encoded image bytes.
            examples:
              basic-url:
                summary: Basic URL
                value:
                  model: grok-imagine-image-quality
                  prompt: A glass observatory above a quiet alpine lake at sunrise
                  aspect_ratio: '16:9'
                  resolution: 1k
                  response_format: url
              base64-2k:
                summary: Base64 and 2K
                value:
                  model: grok-imagine-image-quality
                  prompt: >-
                    A detailed botanical illustration of a blue orchid on ivory
                    paper
                  aspect_ratio: '3:4'
                  resolution: 2k
                  response_format: b64_json
              two-images:
                summary: Two images
                value:
                  model: grok-imagine-image-quality
                  prompt: >-
                    An editorial photograph of a red bicycle beside a modern
                    library
                  'n': 2
                  aspect_ratio: '4:3'
                  resolution: 1k
                  response_format: url
      responses:
        '200':
          description: The generated image results.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - data
                  - usage
                properties:
                  data:
                    type: array
                    minItems: 1
                    description: The generated images.
                    items:
                      type: object
                      additionalProperties: false
                      required:
                        - mime_type
                      oneOf:
                        - required:
                            - url
                        - required:
                            - b64_json
                      properties:
                        url:
                          type: string
                          format: uri
                          description: >-
                            A temporary image URL when `response_format` is
                            `url`.
                        b64_json:
                          type: string
                          description: >-
                            Base64-encoded image bytes when `response_format` is
                            `b64_json`.
                        mime_type:
                          type: string
                          description: The media type of the generated image.
                          example: image/jpeg
                  usage:
                    type: object
                    required:
                      - cost_in_usd_ticks
                    additionalProperties: false
                    description: Usage details for the request.
                    properties:
                      cost_in_usd_ticks:
                        type: integer
                        minimum: 0
                        description: The request cost in USD ticks.
              example:
                data:
                  - url: https://cdn.example.com/generated-image.jpg
                    mime_type: image/jpeg
                usage:
                  cost_in_usd_ticks: 500000000
      x-codeSamples:
        - lang: Shell
          label: Basic URL
          source: |-
            curl https://api.cometapi.com/v1/images/generations \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              --data-binary '{
                "model": "grok-imagine-image-quality",
                "prompt": "A glass observatory above a quiet alpine lake at sunrise",
                "aspect_ratio": "16:9",
                "resolution": "1k",
                "response_format": "url"
              }'
        - lang: Python
          label: Basic URL
          source: |-
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/v1/images/generations",
                headers={
                    "Authorization": f"Bearer {os.environ['COMETAPI_KEY']}",
                    "Content-Type": "application/json",
                },
                json={
                    "model": "grok-imagine-image-quality",
                    "prompt": "A glass observatory above a quiet alpine lake at sunrise",
                    "aspect_ratio": "16:9",
                    "resolution": "1k",
                    "response_format": "url",
                },
                timeout=180,
            )
            response.raise_for_status()
            print(response.json())
        - lang: JavaScript
          label: Basic URL
          source: >-
            const response = await fetch(
              "https://api.cometapi.com/v1/images/generations",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify({
                  model: "grok-imagine-image-quality",
                  prompt: "A glass observatory above a quiet alpine lake at sunrise",
                  aspect_ratio: "16:9",
                  resolution: "1k",
                  response_format: "url",
                }),
              },
            );

            if (!response.ok) throw new Error(`Request failed:
            ${response.status}`);

            console.log(await response.json());
        - lang: Shell
          label: Base64 and 2K
          source: |-
            curl https://api.cometapi.com/v1/images/generations \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              --data-binary '{
                "model": "grok-imagine-image-quality",
                "prompt": "A detailed botanical illustration of a blue orchid on ivory paper",
                "aspect_ratio": "3:4",
                "resolution": "2k",
                "response_format": "b64_json"
              }'
        - lang: Python
          label: Base64 and 2K
          source: |-
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/v1/images/generations",
                headers={
                    "Authorization": f"Bearer {os.environ['COMETAPI_KEY']}",
                    "Content-Type": "application/json",
                },
                json={
                    "model": "grok-imagine-image-quality",
                    "prompt": "A detailed botanical illustration of a blue orchid on ivory paper",
                    "aspect_ratio": "3:4",
                    "resolution": "2k",
                    "response_format": "b64_json",
                },
                timeout=180,
            )
            response.raise_for_status()
            print(response.json())
        - lang: JavaScript
          label: Base64 and 2K
          source: >-
            const response = await fetch(
              "https://api.cometapi.com/v1/images/generations",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify({
                  model: "grok-imagine-image-quality",
                  prompt: "A detailed botanical illustration of a blue orchid on ivory paper",
                  aspect_ratio: "3:4",
                  resolution: "2k",
                  response_format: "b64_json",
                }),
              },
            );

            if (!response.ok) throw new Error(`Request failed:
            ${response.status}`);

            console.log(await response.json());
        - lang: Shell
          label: Two images
          source: |-
            curl https://api.cometapi.com/v1/images/generations \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              --data-binary '{
                "model": "grok-imagine-image-quality",
                "prompt": "An editorial photograph of a red bicycle beside a modern library",
                "n": 2,
                "aspect_ratio": "4:3",
                "resolution": "1k",
                "response_format": "url"
              }'
        - lang: Python
          label: Two images
          source: |-
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/v1/images/generations",
                headers={
                    "Authorization": f"Bearer {os.environ['COMETAPI_KEY']}",
                    "Content-Type": "application/json",
                },
                json={
                    "model": "grok-imagine-image-quality",
                    "prompt": "An editorial photograph of a red bicycle beside a modern library",
                    "n": 2,
                    "aspect_ratio": "4:3",
                    "resolution": "1k",
                    "response_format": "url",
                },
                timeout=180,
            )
            response.raise_for_status()
            print(response.json())
        - lang: JavaScript
          label: Two images
          source: >-
            const response = await fetch(
              "https://api.cometapi.com/v1/images/generations",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify({
                  model: "grok-imagine-image-quality",
                  prompt: "An editorial photograph of a red bicycle beside a modern library",
                  n: 2,
                  aspect_ratio: "4:3",
                  resolution: "1k",
                  response_format: "url",
                }),
              },
            );

            if (!response.ok) throw new Error(`Request failed:
            ${response.status}`);

            console.log(await response.json());
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: Use your CometAPI API key as the bearer value.

````