> ## 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 لتعديل فيديو مصدر باستخدام Prompt نصي، مع الحفاظ على الحركة، والحصول على request_id لاستطلاع النتائج غير المتزامنة.

استخدم نقطة النهاية هذه لتعديل ملف MP4 موجود باستخدام تعليمات نصية. يبقى الناتج أقرب إلى توقيت وتركيب المقطع المصدر مقارنةً بطلب إنشاء جديد من الصفر.

## قبل إرسال الطلب

* قدّم `video.url` يمكن الوصول إليه
* اجعل المقطع المصدر قصيرًا؛ فإرشادات xAI نفسها تحدد الحد الأقصى للتعديلات بحوالي 8.7 ثانية
* استخدم تعليمات مركزة تصف تغييرًا واضحًا واحدًا
* احفظ قيمة `request_id` المعادة، لأن التعديلات تستخدم نفس آلية الاستطلاع المستخدمة في الإنشاء

## تدفق التعديل

<Steps>
  <Step title="إرسال طلب التعديل">
    أرسل URL الفيديو المصدر، وPrompt التعديل، و`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.

````