Replicate
获取 Replicate prediction
通过任务 ID 查询 GET /replicate/v1/predictions/,获取 Replicate prediction 详情以及图像生成工作流中的实时进度。
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
}当你已经拥有一个 Replicate prediction id 后,请使用此端点。它会报告当前任务状态,并在 prediction 完成时返回输出 URL。
先检查这些字段
- 使用
status查看 prediction 是否仍在运行或已经完成 - 使用
output获取已生成资源的 URL - 使用
error查看提供商侧故障 - 当你需要执行耗时或图像数量等详细信息时,查看
metrics
轮询模式
1
先创建 prediction
从 创建 Replicate prediction 开始。
2
按 prediction id 轮询
持续查询,直到
status 变为终态,并且 output 已填充,或者返回提供商错误。3
持久化已完成的资源
将返回的资源 URL 视为交付 URL;如果你需要长期保留,请将它们转存到你自己的存储中。
响应
200 - application/json
Current prediction state.
最后修改于 2026年6月23日
⌘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
}