> ## 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 비디오 편집 생성

> POST /grok/v1/videos/edits를 사용해 텍스트 프롬프트로 원본 비디오를 편집하고, 움직임을 유지하며, 비동기 폴링 결과를 위한 request_id를 받습니다.

이 엔드포인트를 사용하면 텍스트 지시로 기존 MP4를 편집할 수 있습니다. 출력 결과는 새로 생성하는 요청보다 원본 클립의 타이밍과 구도에 더 가깝게 유지됩니다.

## 요청을 보내기 전에

* 접근 가능한 `video.url`을 제공하세요
* 원본 클립은 짧게 유지하세요. xAI 자체 가이드라인에서는 편집 길이를 약 8.7초로 제한합니다
* 하나의 명확한 변경 사항을 설명하는 집중된 지시를 사용하세요
* 편집은 생성과 동일한 폴링 흐름을 사용하므로 반환된 `request_id`를 저장하세요

## 편집 흐름

<Steps>
  <Step title="편집 요청 제출">
    원본 비디오 URL, 편집 프롬프트, 그리고 `model: grok-imagine-video`를 전송하세요.
  </Step>

  <Step title="최종 결과 폴링">
    작업이 완료될 때까지 [xAI 비디오 결과 가져오기](./get-video-generation-results)를 호출하세요.
  </Step>

  <Step title="편집된 자산 저장">
    완성된 출력을 다운로드하거나 반환된 URL을 자체 스토리지 파이프라인으로 이동하세요.
  </Step>
</Steps>

## CometAPI에서 달라지는 점

xAI는 비디오 편집을 생성과 동일한 비동기 라이프사이클로 문서화하며, 선택적인 원본 이미지 대신 원본 비디오를 사용합니다. CometAPI는 이 동작과 동일한 폴링 엔드포인트를 그대로 유지하므로, 편집 워크플로는 여전히 시작 -> 폴링 -> 다운로드입니다.


## OpenAPI

````yaml api/openapi/video/xai/post-video-edit.openapi.json POST /grok/v1/videos/edits
openapi: 3.1.0
info:
  title: Video Edit API
  version: 1.0.0
  description: >-
    Create an asynchronous xAI Grok video edit job from an existing source
    video.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /grok/v1/videos/edits:
    post:
      summary: Create an xAI video edit job
      description: >-
        Start a Grok video editing job from a source MP4 and a natural-language
        edit instruction. Poll the same query endpoint used by video generation.
      operationId: video_edit
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - prompt
                - video
              properties:
                prompt:
                  type: string
                  description: Edit instruction describing the change you want.
                  example: Add snow to the scene.
                model:
                  type: string
                  description: xAI video model id.
                  default: grok-imagine-video
                  example: grok-imagine-video
                video:
                  type: object
                  required:
                    - url
                  properties:
                    url:
                      type: string
                      description: Reachable source MP4 URL.
                  description: >-
                    Source video to edit. xAI documents an input limit of about
                    8.7 seconds.
                output:
                  type: object
                  description: Optional output delivery configuration.
                user:
                  type: string
                  description: Optional end-user identifier.
              default:
                prompt: Add snow to the scene.
                model: grok-imagine-video
                video:
                  url: https://example.com/source.mp4
            examples:
              Edit request:
                summary: Edit request
                value:
                  prompt: Add snow to the scene.
                  video:
                    url: https://example.com/source.mp4
                  model: grok-imagine-video
      responses:
        '200':
          description: Request accepted.
          content:
            application/json:
              schema:
                type: object
                required:
                  - request_id
                properties:
                  request_id:
                    type: string
                    description: Deferred request id used for polling.
                example:
                  request_id: e55813f7-911f-cfa8-208c-9c8e693b4d38
              example:
                request_id: <request_id>
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/grok/v1/videos/edits \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "model": "grok-imagine-video",
                "prompt": "Add snow to the scene.",
                "video": {"url": "https://your-video-host/source.mp4"}
              }'
        - lang: Python
          label: Default
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/grok/v1/videos/edits",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                    "model": "grok-imagine-video",
                    "prompt": "Add snow to the scene.",
                    "video": {"url": "https://your-video-host/source.mp4"},
                },
            )

            task = response.json()
            print(task["request_id"])  # poll GET /grok/v1/videos/{request_id}
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/grok/v1/videos/edits", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                    model: "grok-imagine-video",
                    prompt: "Add snow to the scene.",
                    video: { url: "https://your-video-host/source.mp4" },
                }),
            });


            const task = await response.json();

            console.log(task.request_id); // poll GET
            /grok/v1/videos/{request_id}
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````