Replicate
Отримати передбачення Replicate
Виконайте запит GET /replicate/v1/predictions/, щоб отримати деталі передбачення 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 передбачення Replicate. Він повідомляє поточний стан завдання та повертає URL результатів, коли передбачення завершується.
Спочатку перевірте ці поля
status, щоб побачити, чи передбачення все ще виконується, чи вже завершенеoutputдля URL згенерованих ресурсівerrorдля збоїв на боці провайдераmetrics, якщо вам потрібні відомості про час виконання або кількість зображень
Шаблон опитування
1
Спочатку створіть передбачення
Почніть із Створити передбачення Replicate.
2
Опитуйте за id передбачення
Продовжуйте виконувати запити, доки
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
}