查询所有模型生成任务的状态与结果。
curl --request GET \
--url https://api.crun.ai/api/v1/client/job/TaskInfo \
--header 'x-api-key: <api-key>'import requests
url = "https://api.crun.ai/api/v1/client/job/TaskInfo"
headers = {"x-api-key": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.crun.ai/api/v1/client/job/TaskInfo', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.crun.ai/api/v1/client/job/TaskInfo",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-api-key: <api-key>"
],
]);
$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.crun.ai/api/v1/client/job/TaskInfo"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-api-key", "<api-key>")
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.crun.ai/api/v1/client/job/TaskInfo")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.crun.ai/api/v1/client/job/TaskInfo")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"code": 200,
"message": "success",
"data": {
"task_id": "d6956973-2f17-43d4-8514-af6cc3a2f55d",
"provider": "Google",
"model_version": "nano-banana",
"status": "running",
"param": {
"model": "google/nano-banana",
"callback_url": null,
"input": {
"prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A teenager, painted with ...",
"output_format": "png",
"aspect_ratio": "16:9"
}
},
"create_at": 1768900378,
"result": null,
"credits": 3,
"duration_s": null,
"complete_at": null,
"source": "api"
}
}
{
"code": 200,
"message": "success",
"data": {
"task_id": "d6956973-2f17-43d4-8514-af6cc3a2f55d",
"provider": "Google",
"model_version": "nano-banana",
"status": "success",
"param": {
"model": "google/nano-banana",
"callback_url": null,
"input": {
"prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A teenager, painted with ...",
"output_format": "png",
"aspect_ratio": "16:9"
}
},
"create_at": 1768900378,
"result": {
"code": 200,
"message": "generation success",
"media_urls": [
"https://example.com/example.png"
]
},
"credits": 3,
"duration_s": 137,
"complete_at": 1768900515,
"source": "api"
}
}
{
"code": 200,
"message": "success",
"data": {
"task_id": "d6956973-2f17-43d4-8514-af6cc3a2f55d",
"provider": "Google",
"model_version": "nano-banana",
"status": "failed",
"param": {
"model": "google/nano-banana",
"callback_url": null,
"input": {
"prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A teenager, painted with ...",
"output_format": "png",
"aspect_ratio": "16:9"
}
},
"create_at": 1768900378,
"result": {
"code": 501,
"message": "generation failed"
},
"credits": 0,
"duration_s": 137,
"complete_at": 1768900515,
"source": "api"
}
}
任务
获取任务信息
查询所有模型生成任务的状态与结果。
GET
/
api
/
v1
/
client
/
job
/
TaskInfo
查询所有模型生成任务的状态与结果。
curl --request GET \
--url https://api.crun.ai/api/v1/client/job/TaskInfo \
--header 'x-api-key: <api-key>'import requests
url = "https://api.crun.ai/api/v1/client/job/TaskInfo"
headers = {"x-api-key": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'x-api-key': '<api-key>'}};
fetch('https://api.crun.ai/api/v1/client/job/TaskInfo', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.crun.ai/api/v1/client/job/TaskInfo",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-api-key: <api-key>"
],
]);
$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.crun.ai/api/v1/client/job/TaskInfo"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("x-api-key", "<api-key>")
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.crun.ai/api/v1/client/job/TaskInfo")
.header("x-api-key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.crun.ai/api/v1/client/job/TaskInfo")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["x-api-key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"code": 200,
"message": "success",
"data": {
"task_id": "d6956973-2f17-43d4-8514-af6cc3a2f55d",
"provider": "Google",
"model_version": "nano-banana",
"status": "running",
"param": {
"model": "google/nano-banana",
"callback_url": null,
"input": {
"prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A teenager, painted with ...",
"output_format": "png",
"aspect_ratio": "16:9"
}
},
"create_at": 1768900378,
"result": null,
"credits": 3,
"duration_s": null,
"complete_at": null,
"source": "api"
}
}
{
"code": 200,
"message": "success",
"data": {
"task_id": "d6956973-2f17-43d4-8514-af6cc3a2f55d",
"provider": "Google",
"model_version": "nano-banana",
"status": "success",
"param": {
"model": "google/nano-banana",
"callback_url": null,
"input": {
"prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A teenager, painted with ...",
"output_format": "png",
"aspect_ratio": "16:9"
}
},
"create_at": 1768900378,
"result": {
"code": 200,
"message": "generation success",
"media_urls": [
"https://example.com/example.png"
]
},
"credits": 3,
"duration_s": 137,
"complete_at": 1768900515,
"source": "api"
}
}
{
"code": 200,
"message": "success",
"data": {
"task_id": "d6956973-2f17-43d4-8514-af6cc3a2f55d",
"provider": "Google",
"model_version": "nano-banana",
"status": "failed",
"param": {
"model": "google/nano-banana",
"callback_url": null,
"input": {
"prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A teenager, painted with ...",
"output_format": "png",
"aspect_ratio": "16:9"
}
},
"create_at": 1768900378,
"result": {
"code": 501,
"message": "generation failed"
},
"credits": 0,
"duration_s": 137,
"complete_at": 1768900515,
"source": "api"
}
}
API 端点
GET https://api.crun.ai/api/v1/client/job/TaskInfo
该端点用于查询通过
/api/v1/client/job/CreateTask 接口创建的任务执行状态,并获取任务结果。
它提供统一的查询接口,兼容 模型 分类下的所有模型,无论底层模型如何,均可一致地进行任务追踪与结果获取。查询参数
创建任务时返回的唯一任务标识符。示例:
task_12345678请求示例
curl -X GET "https://api.crun.ai/api/v1/client/job/TaskInfo?task_id=task_12345678" \
-H "X-API-KEY: YOUR_API_KEY" \
-H "Content-Type: application/json"
import requests
API_KEY = "YOUR_API_KEY"
headers = {
"X-API-KEY": API_KEY,
"Content-Type": "application/json"
}
params = {
"task_id": "task_12345678",
}
GET_TASK_STATUS_URL = "https://api.crun.ai/api/v1/client/job/TaskInfo"
response = requests.get(GET_TASK_STATUS_URL, params=params, headers=headers)
print(response.json())
const API_KEY = "YOUR_API_KEY";
const taskId = "task_12345678";
const url = new URL("https://api.crun.ai/api/v1/client/job/TaskInfo");
url.searchParams.append("task_id", taskId);
fetch(url.toString(), {
method: "GET",
headers: {
"X-API-KEY": API_KEY,
"Content-Type": "application/json",
},
})
.then(res => res.json())
.then(data => {
console.log(data);
})
.catch(err => {
console.error("请求失败:", err);
});
{
"code": 200,
"message": "success",
"data": {
"task_id": "d6956973-2f17-43d4-8514-af6cc3a2f55d",
"provider": "Google",
"model_version": "nano-banana",
"status": "running",
"param": {
"model": "google/nano-banana",
"callback_url": null,
"input": {
"prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A teenager, painted with ...",
"output_format": "png",
"aspect_ratio": "16:9"
}
},
"create_at": 1768900378,
"result": null,
"credits": 3,
"duration_s": null,
"complete_at": null,
"source": "api"
}
}
{
"code": 200,
"message": "success",
"data": {
"task_id": "d6956973-2f17-43d4-8514-af6cc3a2f55d",
"provider": "Google",
"model_version": "nano-banana",
"status": "success",
"param": {
"model": "google/nano-banana",
"callback_url": null,
"input": {
"prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A teenager, painted with ...",
"output_format": "png",
"aspect_ratio": "16:9"
}
},
"create_at": 1768900378,
"result": {
"code": 200,
"message": "generation success",
"media_urls": [
"https://example.com/example.png"
]
},
"credits": 3,
"duration_s": 137,
"complete_at": 1768900515,
"source": "api"
}
}
{
"code": 200,
"message": "success",
"data": {
"task_id": "d6956973-2f17-43d4-8514-af6cc3a2f55d",
"provider": "Google",
"model_version": "nano-banana",
"status": "failed",
"param": {
"model": "google/nano-banana",
"callback_url": null,
"input": {
"prompt": "A scene of urban fantasy art. A dynamic graffiti art character. A teenager, painted with ...",
"output_format": "png",
"aspect_ratio": "16:9"
}
},
"create_at": 1768900378,
"result": {
"code": 501,
"message": "generation failed"
},
"credits": 0,
"duration_s": 137,
"complete_at": 1768900515,
"source": "api"
}
}
响应格式
响应状态码。200 表示请求已成功处理(任务已找到并返回,与执行结果无关)。
响应消息,通常为
"success"。包含所有任务信息的任务数据对象。
显示 data 属性
显示 data 属性
任务的唯一标识符。
模型提供商名称。示例:
Google、Wan、Bytedance创建任务时使用的具体模型版本。
任务消耗的积分,任务状态是
pending 或 running 时表示预扣积分,任务状态是 success 或 failed 时表示实际消耗积分。任务创建时间的 Unix 时间戳(秒)。
任务完成时间的 Unix 时间戳(毫秒)。
任务未完成时为
null。任务执行时长(秒)。任务未完成时为 null。
任务创建来源。
任务状态枚举
| 状态 | 描述 | 操作建议 |
|---|---|---|
pending | 任务已入队,等待处理 | 继续轮询 |
running | 任务正在处理中 | 继续轮询 |
success | 任务成功完成 | 访问 result.media_url 获取结果 |
failed | 任务失败 | 访问 result 对象查看错误码和错误信息 |
获取任务结果的最佳实践
推荐轮询间隔
推荐轮询间隔
- 轮询间隔:建议轮询间隔设置为 15 至 30 秒
- 动态调整间隔:对于长时间运行的视频生成任务,建议动态增加轮询间隔
- 延迟首次轮询:首次状态检查前至少等待一个轮询间隔,以减少不必要的请求
- 最大轮询时长:超过 15-20 分钟后应停止并进行排查
过于频繁的轮询可能导致请求被限速。生产环境建议使用回调方式。
使用回调代替轮询
使用回调代替轮询
对于生产环境应用,我们强烈建议在创建任务时使用
callback_url 参数:- 无需轮询:服务器自动接收通知
- 降低 API 成本:避免持续的轮询请求
- 性能更优:任务完成后立即收到通知
- 减少延迟:完成与通知之间无延迟
推荐使用此方式
处理已完成的任务
处理已完成的任务
当
status 为 success 时:- 从响应的
result字段获取任务结果 - 从
result.media_urls中提取生成的媒体 URL - 将媒体文件下载至您自己的存储空间
- 将结果元数据持久化至您的存储或数据库
重要提示:生成的媒体 URL 通常在 14 天后永久删除
常见错误码
| 错误码 | 描述 | 解决方案 |
|---|---|---|
401 | 未授权 - API 密钥无效或缺失 | 检查您的 API 密钥 |
404 | 任务未找到 | 验证 task_id 是否正确 |
429 | 超出请求频率限制 | 降低请求频率 |
500 | 服务器内部错误 | 几分钟后重试 |
501 | 生成失败 | 查看 result 对象获取错误码和错误信息 |
频率限制
- 最大查询速率:每账号每秒最多 15 次请求
- 推荐间隔:每次轮询间隔 15-30 秒
相关资源
模型概览
探索所有可用模型
获取账户额度
查看您的剩余积分
授权
所有 API 均需通过 API Key 进行身份验证。
获取 API Key:
- 访问 API Key 管理页面 获取您的 API Key
使用方式: 将以下内容添加至请求头:
x-api-key: YOUR_API_KEY
注意事项:
- 请妥善保管您的 API Key,切勿与他人共享
- 若怀疑 API Key 已泄露,请立即在管理页面进行重置
查询参数
用于获取任务结果的任务 ID。
Required string length:
36示例:
"task_1234567"
响应
任务信息获取成功或任务未找到。
响应状态码
- 200: 成功 - 请求已成功处理
- 401: 未授权 - 身份凭证缺失或无效
- 402: 额度不足 - 账户余额不足以完成本次操作
- 404: 未找到 - 请求的资源或端点不存在
- 422: 验证错误 - 请求参数未通过验证
- 429: 请求限速 - 该资源的请求次数已超出限制
- 455: 服务不可用 - 系统正在维护中
- 500: 服务器错误 - 处理请求时发生意外错误
- 501: 生成失败 - 内容生成任务失败
- 505: 功能已禁用 - 所请求的功能当前已被禁用
响应消息
任务记录及结果信息。
Show child attributes
Show child attributes
此页面对您有帮助吗?
⌘I
