> ## 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.

# Opprett en video med Grok

> Opprett asynkrone Grok Imagine Video 1.5-oppgaver fra tekst, et kildebilde eller bilde- og forhåndsinnstilte stemmereferanser.

Bruk dette endepunktet for å starte en Grok-videooppgave fra tekst, et kildebilde eller referanseinndata. Det returnerer umiddelbart en `request_id`, så behandle det som det første trinnet i en asynkron arbeidsflyt.

Send alltid `model: grok-imagine-video-1.5` eksplisitt. `model` og `prompt` kreves for 1.5-forespørselsformene som dokumenteres her.

## Velg en inndatamodus

| Modus               | Forespørselsfelt                                                    | Regler                                                                                                                       |
| ------------------- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| Tekst-til-video     | `prompt`                                                            | Utelat `image`, `reference_images` og `reference_audios`.                                                                    |
| Bilde-til-video     | `prompt`, `image.url`                                               | `image.url` godtar en offentlig bilde-URL eller en bilde-data-URI. Ikke kombiner `image` med referanseinndata.               |
| Referanse-til-video | `prompt` og minst én av `reference_images` eller `reference_audios` | Send opptil 7 referansebilder og opptil 3 forhåndsinnstilte stemmer. Utdata fra referanse-til-video er begrenset til `720p`. |

For en data URI bruker du `data:image/png;base64,<BASE64_IMAGE_DATA>`. Hvert `reference_images`-element bruker det samme `url`-feltet. Et referanselydelement bruker en forhåndsinnstilt `voice_id`, for eksempel `eve`. I Prompt kan tagger som `<IMAGE_0>` og `<AUDIO_0>` identifisere den tilsvarende referansen.

## Begynn med en liten forespørsel

* Bruk `model: grok-imagine-video-1.5`
* For den første forespørselen bør du holde `duration` på `1` og `resolution` på `480p`
* Hold `prompt` eksplisitt slik at scenen og bevegelsen er tydelige
* Legg til én inndatamodus om gangen før du kombinerer referansebilder og stemmer

## Varighet og oppløsning

| Innstilling    | Støttede verdier                                  | Standard                   | Atferd ved grenseverdier                                                                                               |
| -------------- | ------------------------------------------------- | -------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `duration`     | heltall `1`-`15`                                  | `8`                        | Bruk kortere klipp ved første tester; lengre klipp koster mer og tar lengre tid å fullføre.                            |
| `resolution`   | `480p`, `720p`, `1080p`                           | `480p`                     | Forespørsler med høyere oppløsning koster mer og tar lengre tid å fullføre. Referanse-til-video støtter opptil `720p`. |
| `aspect_ratio` | `1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `3:2`, `2:3` | `16:9` for tekst-til-video | For bilde-til-video bevarer utelatelse kildebildets sideforhold.                                                       |

Genererte videoer inkluderer et lydspor. Angi `duration`, `resolution` og `aspect_ratio` eksplisitt når applikasjonen din avhenger av et bestemt utdataformat.

## Oppgaveflyt

<Steps>
  <Step title="Opprett oppgaven">
    Send modellen, Prompt og eventuelle inndata, og lagre den returnerte `request_id`.
  </Step>

  <Step title="Sjekk om den er fullført">
    Kall [Hent xAI-videoresultater](./get-video-generation-results) til `status` på toppnivå blir `done`, `failed` eller `expired`. Et første svar kan bare inneholde den gjentatte `request_id` mens oppgavemetadata klargjøres.
  </Step>

  <Step title="Lagre utdataene">
    Kopier den endelige `video.url` til din egen lagring hvis du trenger den etter det midlertidige leveringsvinduet.
  </Step>
</Steps>


## OpenAPI

````yaml api/openapi/video/xai/post-video-generation.openapi.json POST /grok/v1/videos/generations
openapi: 3.1.0
info:
  title: Grok Video Generation API
  version: 1.0.0
  description: >-
    Create an asynchronous Grok Imagine Video 1.5 job from text, a source image,
    or reference inputs.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /grok/v1/videos/generations:
    post:
      summary: Create a Grok video generation job
      description: >-
        Start a Grok Imagine Video 1.5 job. Save the returned `request_id`, then
        poll the result endpoint until the top-level status reaches a terminal
        state.
      operationId: video_generation
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required:
                - model
                - prompt
              allOf:
                - not:
                    required:
                      - image
                      - reference_images
                - not:
                    required:
                      - image
                      - reference_audios
                - if:
                    anyOf:
                      - required:
                          - reference_images
                      - required:
                          - reference_audios
                  then:
                    properties:
                      resolution:
                        description: Reference-to-video resolution constraint.
                        enum:
                          - 480p
                          - 720p
              properties:
                model:
                  type: string
                  enum:
                    - grok-imagine-video-1.5
                  description: >-
                    The Grok video model ID. Send this field explicitly so the
                    request uses Grok Imagine Video 1.5.
                  example: grok-imagine-video-1.5
                prompt:
                  type: string
                  minLength: 1
                  description: >-
                    A description of the scene, motion, and audio.
                    Reference-to-video prompts can identify inputs with tags
                    such as `<IMAGE_0>` and `<AUDIO_0>`.
                  example: A paper boat glides across a quiet pond at sunrise.
                duration:
                  type: integer
                  minimum: 1
                  maximum: 15
                  default: 8
                  description: >-
                    The output duration in seconds. Use an integer from 1
                    through 15.
                aspect_ratio:
                  type: string
                  description: >-
                    The output aspect ratio. Text-to-video uses `16:9` when
                    omitted. Image-to-video uses the source image's aspect ratio
                    when omitted.
                  enum:
                    - '1:1'
                    - '16:9'
                    - '9:16'
                    - '4:3'
                    - '3:4'
                    - '3:2'
                    - '2:3'
                  example: '16:9'
                resolution:
                  type: string
                  description: >-
                    The output resolution. Reference-to-video requests support
                    `480p` and `720p`; text-to-video and image-to-video also
                    support `1080p`.
                  enum:
                    - 480p
                    - 720p
                    - 1080p
                  default: 480p
                image:
                  type: object
                  additionalProperties: false
                  required:
                    - url
                  properties:
                    url:
                      type: string
                      description: >-
                        A public image URL or an image data URI such as
                        `data:image/png;base64,<BASE64_IMAGE_DATA>`.
                  description: >-
                    The source image for image-to-video. Do not combine this
                    field with `reference_images` or `reference_audios`.
                reference_images:
                  type: array
                  minItems: 1
                  maxItems: 7
                  description: >-
                    Visual references for reference-to-video. Each item accepts
                    a public image URL or image data URI. Do not combine this
                    field with `image`.
                  items:
                    type: object
                    additionalProperties: false
                    required:
                      - url
                    description: One visual reference.
                    properties:
                      url:
                        type: string
                        description: A public image URL or an image data URI.
                reference_audios:
                  type: array
                  minItems: 1
                  maxItems: 3
                  description: >-
                    Preset voice references for reference-to-video. Do not
                    combine this field with `image`.
                  items:
                    type: object
                    additionalProperties: false
                    required:
                      - voice_id
                    description: One preset voice reference.
                    properties:
                      voice_id:
                        type: string
                        minLength: 1
                        description: The preset voice ID, such as `eve`.
            examples:
              text-to-video:
                summary: Text to video
                value:
                  model: grok-imagine-video-1.5
                  prompt: A paper boat glides across a quiet pond at sunrise.
                  duration: 1
                  aspect_ratio: '16:9'
                  resolution: 480p
              image-url:
                summary: Image URL
                value:
                  model: grok-imagine-video-1.5
                  prompt: >-
                    Animate the clouds with a slow camera move and natural
                    motion.
                  image:
                    url: >-
                      https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png
                  duration: 1
                  aspect_ratio: '16:9'
                  resolution: 720p
              image-data-uri:
                summary: Image data URI
                value:
                  model: grok-imagine-video-1.5
                  prompt: Animate the clouds drifting across the sky.
                  image:
                    url: data:image/png;base64,<BASE64_IMAGE_DATA>
                  duration: 1
                  aspect_ratio: '16:9'
                  resolution: 480p
              reference-image:
                summary: Reference image
                value:
                  model: grok-imagine-video-1.5
                  prompt: >-
                    Use <IMAGE_0> as the visual reference for a gentle cinematic
                    pan.
                  reference_images:
                    - url: >-
                        https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png
                  duration: 1
                  aspect_ratio: '16:9'
                  resolution: 720p
              reference-image-and-audio:
                summary: Reference image and preset voice
                value:
                  model: grok-imagine-video-1.5
                  prompt: >-
                    Use <IMAGE_0> as the visual reference while <AUDIO_0> says
                    Welcome to the observatory.
                  reference_images:
                    - url: >-
                        https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png
                  reference_audios:
                    - voice_id: eve
                  duration: 1
                  aspect_ratio: '16:9'
                  resolution: 720p
      responses:
        '200':
          description: Request accepted.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - request_id
                properties:
                  request_id:
                    type: string
                    description: >-
                      The deferred request ID used to poll `GET
                      /grok/v1/videos/{request_id}`.
                example:
                  request_id: <request_id>
              example:
                request_id: <request_id>
      x-codeSamples:
        - lang: Shell
          label: Text to video
          source: |-
            curl https://api.cometapi.com/grok/v1/videos/generations \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              --data-binary '{
              "model": "grok-imagine-video-1.5",
              "prompt": "A paper boat glides across a quiet pond at sunrise.",
              "duration": 1,
              "aspect_ratio": "16:9",
              "resolution": "480p"
            }'
        - lang: Python
          label: Text to video
          source: |-
            import os
            import requests

            payload = {
                "model": "grok-imagine-video-1.5",
                "prompt": "A paper boat glides across a quiet pond at sunrise.",
                "duration": 1,
                "aspect_ratio": "16:9",
                "resolution": "480p"
            }

            response = requests.post(
                "https://api.cometapi.com/grok/v1/videos/generations",
                headers={
                    "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
                    "Content-Type": "application/json",
                },
                json=payload,
                timeout=180,
            )
            response.raise_for_status()
            print(response.json()["request_id"])
        - lang: JavaScript
          label: Text to video
          source: >-
            const payload = {
              "model": "grok-imagine-video-1.5",
              "prompt": "A paper boat glides across a quiet pond at sunrise.",
              "duration": 1,
              "aspect_ratio": "16:9",
              "resolution": "480p"
            };


            const response = await fetch(
              "https://api.cometapi.com/grok/v1/videos/generations",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify(payload),
              },
            );

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

            console.log((await response.json()).request_id);
        - lang: Shell
          label: Image URL
          source: |-
            curl https://api.cometapi.com/grok/v1/videos/generations \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              --data-binary '{
              "model": "grok-imagine-video-1.5",
              "prompt": "Animate the clouds with a slow camera move and natural motion.",
              "image": {
                "url": "https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png"
              },
              "duration": 1,
              "aspect_ratio": "16:9",
              "resolution": "720p"
            }'
        - lang: Python
          label: Image URL
          source: |-
            import os
            import requests

            payload = {
                "model": "grok-imagine-video-1.5",
                "prompt": "Animate the clouds with a slow camera move and natural motion.",
                "image": {
                    "url": "https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png"
                },
                "duration": 1,
                "aspect_ratio": "16:9",
                "resolution": "720p"
            }

            response = requests.post(
                "https://api.cometapi.com/grok/v1/videos/generations",
                headers={
                    "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
                    "Content-Type": "application/json",
                },
                json=payload,
                timeout=180,
            )
            response.raise_for_status()
            print(response.json()["request_id"])
        - lang: JavaScript
          label: Image URL
          source: >-
            const payload = {
              "model": "grok-imagine-video-1.5",
              "prompt": "Animate the clouds with a slow camera move and natural motion.",
              "image": {
                "url": "https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png"
              },
              "duration": 1,
              "aspect_ratio": "16:9",
              "resolution": "720p"
            };


            const response = await fetch(
              "https://api.cometapi.com/grok/v1/videos/generations",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify(payload),
              },
            );

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

            console.log((await response.json()).request_id);
        - lang: Shell
          label: Image data URI
          source: |-
            {
              printf '%s' '{"model":"grok-imagine-video-1.5","prompt":"Animate the clouds drifting across the sky.","image":{"url":"data:image/png;base64,'
              base64 < source.png | tr -d '\n'
              printf '%s' '"},"duration":1,"aspect_ratio":"16:9","resolution":"480p"}'
            } | curl https://api.cometapi.com/grok/v1/videos/generations \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              --data-binary @-
        - lang: Python
          label: Image data URI
          source: |-
            import base64
            import os
            import requests

            with open("source.png", "rb") as image_file:
                image_b64 = base64.b64encode(image_file.read()).decode()

            payload = {
                "model": "grok-imagine-video-1.5",
                "prompt": "Animate the clouds drifting across the sky.",
                "image": {
                    "url": "data:image/png;base64," + image_b64
                },
                "duration": 1,
                "aspect_ratio": "16:9",
                "resolution": "480p"
            }

            response = requests.post(
                "https://api.cometapi.com/grok/v1/videos/generations",
                headers={
                    "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
                    "Content-Type": "application/json",
                },
                json=payload,
                timeout=180,
            )
            response.raise_for_status()
            print(response.json()["request_id"])
        - lang: JavaScript
          label: Image data URI
          source: >-
            import { readFile } from "node:fs/promises";


            const imageB64 = (await readFile("source.png")).toString("base64");


            const payload = {
              "model": "grok-imagine-video-1.5",
              "prompt": "Animate the clouds drifting across the sky.",
              "image": {
                "url": `data:image/png;base64,${imageB64}`
              },
              "duration": 1,
              "aspect_ratio": "16:9",
              "resolution": "480p"
            };


            const response = await fetch(
              "https://api.cometapi.com/grok/v1/videos/generations",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify(payload),
              },
            );

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

            console.log((await response.json()).request_id);
        - lang: Shell
          label: Reference image
          source: |-
            curl https://api.cometapi.com/grok/v1/videos/generations \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              --data-binary '{
              "model": "grok-imagine-video-1.5",
              "prompt": "Use <IMAGE_0> as the visual reference for a gentle cinematic pan.",
              "reference_images": [
                {
                  "url": "https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png"
                }
              ],
              "duration": 1,
              "aspect_ratio": "16:9",
              "resolution": "720p"
            }'
        - lang: Python
          label: Reference image
          source: |-
            import os
            import requests

            payload = {
                "model": "grok-imagine-video-1.5",
                "prompt": "Use <IMAGE_0> as the visual reference for a gentle cinematic pan.",
                "reference_images": [
                    {
                        "url": "https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png"
                    }
                ],
                "duration": 1,
                "aspect_ratio": "16:9",
                "resolution": "720p"
            }

            response = requests.post(
                "https://api.cometapi.com/grok/v1/videos/generations",
                headers={
                    "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
                    "Content-Type": "application/json",
                },
                json=payload,
                timeout=180,
            )
            response.raise_for_status()
            print(response.json()["request_id"])
        - lang: JavaScript
          label: Reference image
          source: >-
            const payload = {
              "model": "grok-imagine-video-1.5",
              "prompt": "Use <IMAGE_0> as the visual reference for a gentle cinematic pan.",
              "reference_images": [
                {
                  "url": "https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png"
                }
              ],
              "duration": 1,
              "aspect_ratio": "16:9",
              "resolution": "720p"
            };


            const response = await fetch(
              "https://api.cometapi.com/grok/v1/videos/generations",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify(payload),
              },
            );

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

            console.log((await response.json()).request_id);
        - lang: Shell
          label: Reference image and preset voice
          source: |-
            curl https://api.cometapi.com/grok/v1/videos/generations \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              --data-binary '{
              "model": "grok-imagine-video-1.5",
              "prompt": "Use <IMAGE_0> as the visual reference while <AUDIO_0> says Welcome to the observatory.",
              "reference_images": [
                {
                  "url": "https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png"
                }
              ],
              "reference_audios": [
                {
                  "voice_id": "eve"
                }
              ],
              "duration": 1,
              "aspect_ratio": "16:9",
              "resolution": "720p"
            }'
        - lang: Python
          label: Reference image and preset voice
          source: |-
            import os
            import requests

            payload = {
                "model": "grok-imagine-video-1.5",
                "prompt": "Use <IMAGE_0> as the visual reference while <AUDIO_0> says Welcome to the observatory.",
                "reference_images": [
                    {
                        "url": "https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png"
                    }
                ],
                "reference_audios": [
                    {
                        "voice_id": "eve"
                    }
                ],
                "duration": 1,
                "aspect_ratio": "16:9",
                "resolution": "720p"
            }

            response = requests.post(
                "https://api.cometapi.com/grok/v1/videos/generations",
                headers={
                    "Authorization": "Bearer " + os.environ["COMETAPI_KEY"],
                    "Content-Type": "application/json",
                },
                json=payload,
                timeout=180,
            )
            response.raise_for_status()
            print(response.json()["request_id"])
        - lang: JavaScript
          label: Reference image and preset voice
          source: >-
            const payload = {
              "model": "grok-imagine-video-1.5",
              "prompt": "Use <IMAGE_0> as the visual reference while <AUDIO_0> says Welcome to the observatory.",
              "reference_images": [
                {
                  "url": "https://apidoc.cometapi.com/images/image/gemini/6100640_569429.png"
                }
              ],
              "reference_audios": [
                {
                  "voice_id": "eve"
                }
              ],
              "duration": 1,
              "aspect_ratio": "16:9",
              "resolution": "720p"
            };


            const response = await fetch(
              "https://api.cometapi.com/grok/v1/videos/generations",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify(payload),
              },
            );

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

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

````