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

# xAI 비디오 결과 가져오기

> GET /grok/v1/videos/{request_id}를 사용해 xAI 비디오 생성 상태를 폴링하고, 처리가 완료되면 최종 비디오 URL을 가져옵니다.

이미 `request_id`가 있는 경우 이 엔드포인트를 사용하세요. xAI 작업이 아직 실행 중인지 알려주고, 준비되면 최종 비디오 메타데이터를 반환합니다.

## 먼저 이 필드를 확인하세요

* 작업이 수락되었지만 결과가 아직 준비되지 않은 경우 `request_id`
* xAI 작업 상태를 나타내는 `status`; `done`에 도달할 때까지 계속 폴링하세요
* 반환되는 경우 완료 비율을 나타내는 `progress`
* 렌더링이 완료되면 `video.url`

## 폴링 루프

<Steps>
  <Step title="먼저 비디오를 생성하거나 편집하세요">
    [Create an xAI video](./video-generation) 또는 [Create an xAI video edit](./video-edit)부터 시작한 다음, 반환된 `request_id`를 복사하세요.
  </Step>

  <Step title="status가 done이 될 때까지 계속 폴링하세요">
    응답이 `request_id`만 그대로 반환하는 경우 몇 초 기다렸다가 다시 폴링하세요. `status`가 나타나면 이를 중지 조건으로 사용하세요.
  </Step>

  <Step title="완성된 파일을 저장하세요">
    최종 `video.url`은 xAI 문서에서 임시 URL로 안내하고 있으므로 즉시 다운로드하거나 복사하세요.
  </Step>
</Steps>


## OpenAPI

````yaml api/openapi/video/xai/get-get-video-generation-results.openapi.json GET /grok/v1/videos/{request_id}
openapi: 3.1.0
info:
  title: Get Video Generation Results API
  version: 1.0.0
  description: >-
    Query an xAI Grok video job created through CometAPI and read the final
    temporary video URL when the job is complete.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /grok/v1/videos/{request_id}:
    get:
      summary: Query an xAI video job
      description: >-
        Use the request_id from the generation or edit endpoint to poll status
        until the job completes. xAI documents the final video URL as temporary.
      operationId: get_video_generation_results
      parameters:
        - name: request_id
          in: path
          required: true
          description: Deferred request id returned by the create or edit endpoint.
          schema:
            type: string
      responses:
        '200':
          description: Current xAI video task state.
          content:
            application/json:
              schema:
                type: object
                properties:
                  request_id:
                    type: string
                    description: >-
                      Returned when the request is accepted but result metadata
                      is not ready yet.
                  model:
                    type: string
                    description: xAI video model id.
                  usage:
                    type: object
                    properties:
                      cost_in_usd_ticks:
                        type: integer
                        description: Billing usage value returned by xAI.
                    description: >-
                      Billing metadata. `cost_in_usd_ticks` reports the cost in
                      provider ticks.
                  video:
                    type: object
                    description: >-
                      Generated video metadata. Present when the job has
                      completed.
                    properties:
                      url:
                        type: string
                        description: Temporary URL for the generated MP4.
                      duration:
                        type: integer
                        description: Video duration in seconds.
                      respect_moderation:
                        type: boolean
                        description: Moderation flag returned with the video.
                  status:
                    type: string
                    description: xAI job state. `done` means the video metadata is ready.
                    enum:
                      - queued
                      - processing
                      - done
                      - failed
                      - expired
                  progress:
                    type: integer
                    description: Completion percentage when returned.
                  error:
                    description: Error details when the job fails.
                    nullable: true
                    oneOf:
                      - type: string
                      - type: object
              examples:
                accepted:
                  summary: Task accepted, keep polling
                  value:
                    request_id: <request_id>
                done:
                  summary: Task finished successfully
                  value:
                    model: grok-imagine-video-1.5
                    usage:
                      cost_in_usd_ticks: 500000000
                    video:
                      url: https://example.com/xai-video.mp4
                      duration: 1
                      respect_moderation: true
                    status: done
                    progress: 100
              example:
                model: grok-imagine-video-1.5
                usage:
                  cost_in_usd_ticks: 500000000
                video:
                  url: https://example.com/xai-video.mp4
                  duration: 1
                  respect_moderation: true
                status: done
                progress: 100
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            REQUEST_ID="<request_id>"

            curl "https://api.cometapi.com/grok/v1/videos/$REQUEST_ID" \
              -H "Authorization: Bearer $COMETAPI_KEY"
        - lang: Shell
          label: Poll until done
          source: |
            REQUEST_ID="<request_id>"

            while true; do
              STATUS=$(curl -s "https://api.cometapi.com/grok/v1/videos/$REQUEST_ID" \
                -H "Authorization: Bearer $COMETAPI_KEY" | python3 -c "import json,sys; print(json.load(sys.stdin)['status'])")
              echo "status: $STATUS"
              case "$STATUS" in done | failed | expired) break;; esac
              sleep 20
            done
        - lang: Python
          label: Default
          source: |
            import os
            import requests

            request_id = "<request_id>"

            response = requests.get(
                f"https://api.cometapi.com/grok/v1/videos/{request_id}",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
            )

            print(response.json())
        - lang: Python
          label: Poll until done
          source: |
            import os
            import time
            import requests

            request_id = "<request_id>"
            headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}

            while True:
                task = requests.get(
                    f"https://api.cometapi.com/grok/v1/videos/{request_id}", headers=headers
                ).json()
                print(task.get("status"), task.get("progress"))
                if task.get("status") in ("done", "failed", "expired"):
                    break
                time.sleep(10)

            if task.get("status") == "done":
                print(task["video"]["url"])
        - lang: JavaScript
          label: Default
          source: >
            const requestId = "<request_id>";


            const response = await
            fetch(`https://api.cometapi.com/grok/v1/videos/${requestId}`, {
                headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
            });


            console.log(await response.json());
        - lang: JavaScript
          label: Poll until done
          source: >
            const requestId = "<request_id>";

            const headers = { Authorization: `Bearer
            ${process.env.COMETAPI_KEY}` };


            let task;

            while (true) {
                task = await (await fetch(`https://api.cometapi.com/grok/v1/videos/${requestId}`, { headers })).json();
                console.log(task.status, task.progress);
                if (["done", "failed", "expired"].includes(task.status)) break;
                await new Promise((resolve) => setTimeout(resolve, 10000));
            }


            if (task.status === "done") console.log(task.video.url);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````