xAI
Creare un video edit xAI
Usa POST /grok/v1/videos/edits per modificare un video sorgente con un prompt testuale, preservare il movimento e ottenere un request_id per interrogare in modo asincrono i risultati.
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>"
}Usa questo endpoint per modificare un MP4 esistente con un’istruzione testuale. L’output rimane più vicino alla tempistica e alla composizione della clip sorgente rispetto a una richiesta di generazione da zero.
Prima di inviare la richiesta
- Fornisci un
video.urlraggiungibile - Mantieni breve la clip sorgente; la guida di xAI limita le modifiche a circa 8,7 secondi
- Usa un’istruzione mirata che descriva un solo cambiamento chiaro
- Salva il
request_idrestituito, perché le modifiche usano lo stesso flusso di polling della generazione
Flusso di modifica
1
Invia la richiesta di modifica
Invia l’URL del video sorgente, il prompt di modifica e
model: grok-imagine-video.2
Interroga il risultato finale
Chiama Get xAI video results finché il job non è terminato.
3
Archivia l'asset modificato
Scarica l’output finale oppure sposta l’URL restituito nella tua pipeline di archiviazione.
Cosa cambia su CometAPI
xAI documenta la modifica video come lo stesso ciclo di vita asincrono della generazione, ma con un video sorgente invece di un’immagine sorgente opzionale. CometAPI mantiene questo comportamento e lo stesso endpoint di polling, quindi il tuo flusso di modifica resta comunque avvio -> polling -> download.Autorizzazioni
Corpo
application/json
Ultima modifica il 23 giugno 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>"
}