xAI
Tạo một video chỉnh sửa xAI
Sử dụng POST /grok/v1/videos/edits để chỉnh sửa video nguồn bằng một prompt văn bản, giữ nguyên chuyển động và nhận request_id để polling kết quả bất đồng bộ.
POST
/
grok
/
v1
/
videos
/
edits
cURL
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"}
}'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}
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}
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/grok/v1/videos/edits",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'Add snow to the scene.',
'video' => [
'url' => 'https://example.com/source.mp4'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/grok/v1/videos/edits"
payload := strings.NewReader("{\n \"prompt\": \"Add snow to the scene.\",\n \"video\": {\n \"url\": \"https://example.com/source.mp4\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cometapi.com/grok/v1/videos/edits")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"Add snow to the scene.\",\n \"video\": {\n \"url\": \"https://example.com/source.mp4\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/grok/v1/videos/edits")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"Add snow to the scene.\",\n \"video\": {\n \"url\": \"https://example.com/source.mp4\"\n }\n}"
response = http.request(request)
puts response.read_body{
"request_id": "<request_id>"
}Sử dụng endpoint này để chỉnh sửa một tệp MP4 hiện có bằng một chỉ dẫn văn bản. Đầu ra sẽ bám sát hơn với nhịp thời gian và bố cục của clip nguồn so với một yêu cầu tạo mới.
Trước khi gửi request
- Cung cấp
video.urlcó thể truy cập được - Giữ clip nguồn ngắn; hướng dẫn riêng của xAI giới hạn chỉnh sửa ở khoảng 8,7 giây
- Sử dụng một chỉ dẫn tập trung mô tả một thay đổi rõ ràng
- Lưu
request_idđược trả về, vì chỉnh sửa sử dụng cùng luồng polling như tạo video
Quy trình chỉnh sửa
1
Gửi yêu cầu chỉnh sửa
Gửi URL video nguồn, prompt chỉnh sửa và
model: grok-imagine-video.2
Polling để lấy kết quả cuối cùng
Gọi Lấy kết quả video xAI cho đến khi tác vụ hoàn tất.
3
Lưu trữ tài nguyên đã chỉnh sửa
Tải đầu ra hoàn tất xuống hoặc đưa URL được trả về vào pipeline lưu trữ của riêng bạn.
Những gì thay đổi trên CometAPI
xAI mô tả việc chỉnh sửa video có cùng vòng đời bất đồng bộ như tạo video, chỉ khác là dùng video nguồn thay vì hình ảnh nguồn tùy chọn. CometAPI giữ nguyên hành vi đó và cùng endpoint polling, vì vậy quy trình chỉnh sửa của bạn vẫn là bắt đầu -> polling -> tải xuống.Nội dung
application/json
Lần sửa đổi cuối 23 tháng 6, 2026
⌘I
cURL
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"}
}'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}
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}
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/grok/v1/videos/edits",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'Add snow to the scene.',
'video' => [
'url' => 'https://example.com/source.mp4'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/grok/v1/videos/edits"
payload := strings.NewReader("{\n \"prompt\": \"Add snow to the scene.\",\n \"video\": {\n \"url\": \"https://example.com/source.mp4\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.cometapi.com/grok/v1/videos/edits")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"Add snow to the scene.\",\n \"video\": {\n \"url\": \"https://example.com/source.mp4\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/grok/v1/videos/edits")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"Add snow to the scene.\",\n \"video\": {\n \"url\": \"https://example.com/source.mp4\"\n }\n}"
response = http.request(request)
puts response.read_body{
"request_id": "<request_id>"
}