Replicate
Получить prediction Replicate
Выполните запрос GET /replicate/v1/predictions/, чтобы получить сведения о prediction Replicate и прогресс в реальном времени по ID задачи для рабочих процессов генерации изображений.
GET
/
replicate
/
v1
/
predictions
/
{id}
cURL
curl "https://api.cometapi.com/replicate/v1/predictions/<prediction_id>" \
-H "Authorization: Bearer $COMETAPI_KEY"import os
import time
import requests
prediction_id = "<prediction_id>"
headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}
while True:
prediction = requests.get(
f"https://api.cometapi.com/replicate/v1/predictions/{prediction_id}",
headers=headers,
).json()
print(prediction["status"])
if prediction["status"] in ("succeeded", "failed", "canceled"):
break
time.sleep(3)
if prediction["status"] == "succeeded":
print(prediction["output"])
const predictionId = "<prediction_id>";
const headers = { Authorization: `Bearer ${process.env.COMETAPI_KEY}` };
let prediction;
while (true) {
prediction = await (await fetch(
`https://api.cometapi.com/replicate/v1/predictions/${predictionId}`, { headers }
)).json();
console.log(prediction.status);
if (["succeeded", "failed", "canceled"].includes(prediction.status)) break;
await new Promise((resolve) => setTimeout(resolve, 3000));
}
if (prediction.status === "succeeded") console.log(prediction.output);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/replicate/v1/predictions/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/replicate/v1/predictions/{id}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.cometapi.com/replicate/v1/predictions/{id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/replicate/v1/predictions/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"id": "<prediction_id>",
"model": "black-forest-labs/flux-schnell",
"status": "succeeded",
"output": [
"https://replicate.delivery/xezq/.../out-0.webp"
],
"error": null
}Используйте этот endpoint, если у вас уже есть id prediction Replicate. Он сообщает текущее состояние задачи и возвращает URL результатов, когда prediction завершается.
Сначала проверьте эти поля
status, чтобы понять, prediction все еще выполняется или уже завершенoutputдля URL сгенерированных ресурсовerrorдля ошибок на стороне провайдераmetrics, если вам нужны сведения о времени выполнения или количестве изображений
Шаблон polling
1
Сначала создайте prediction
Начните с Создать prediction Replicate.
2
Опрашивайте по id prediction
Продолжайте выполнять запросы, пока
status не станет терминальным и output либо не заполнится, либо не будет возвращена ошибка провайдера.3
Сохраняйте готовые ресурсы
Считайте возвращенные URL ресурсов URL доставки и перенесите их в собственное хранилище, если вам требуется длительное хранение.
Ответ
200 - application/json
Current prediction state.
Последнее изменение 23 июня 2026 г.
⌘I
cURL
curl "https://api.cometapi.com/replicate/v1/predictions/<prediction_id>" \
-H "Authorization: Bearer $COMETAPI_KEY"import os
import time
import requests
prediction_id = "<prediction_id>"
headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}
while True:
prediction = requests.get(
f"https://api.cometapi.com/replicate/v1/predictions/{prediction_id}",
headers=headers,
).json()
print(prediction["status"])
if prediction["status"] in ("succeeded", "failed", "canceled"):
break
time.sleep(3)
if prediction["status"] == "succeeded":
print(prediction["output"])
const predictionId = "<prediction_id>";
const headers = { Authorization: `Bearer ${process.env.COMETAPI_KEY}` };
let prediction;
while (true) {
prediction = await (await fetch(
`https://api.cometapi.com/replicate/v1/predictions/${predictionId}`, { headers }
)).json();
console.log(prediction.status);
if (["succeeded", "failed", "canceled"].includes(prediction.status)) break;
await new Promise((resolve) => setTimeout(resolve, 3000));
}
if (prediction.status === "succeeded") console.log(prediction.output);
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/replicate/v1/predictions/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.cometapi.com/replicate/v1/predictions/{id}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.cometapi.com/replicate/v1/predictions/{id}")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/replicate/v1/predictions/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"id": "<prediction_id>",
"model": "black-forest-labs/flux-schnell",
"status": "succeeded",
"output": [
"https://replicate.delivery/xezq/.../out-0.webp"
],
"error": null
}