概述
xPilot v1 API 提供视频、图片、文字生成的编程接口。所有端点需要有效的 API Key,采用 credit 计费。
Base URL:
https://xpilot.jytech.us/api/v1认证:
Authorization: Bearer xp_...频率限制:30 请求/分钟 (每个 API Key)
格式:JSON
认证
在 设置 > API 密钥 中创建 API Key,在每个请求的 Authorization header 中携带:
bashcurl -H "Authorization: Bearer xp_your_api_key_here" \
https://xpilot.jytech.us/api/v1/models请妥善保管 API Key,不要在前端代码或公开仓库中暴露。
获取模型列表
GET
/api/v1/models返回所有可用模型,按类型(text, video, image)分组,包含定价信息。
bashcurl -H "Authorization: Bearer xp_..." \
https://xpilot.jytech.us/api/v1/models响应:
json{
"models": {
"text": [
{ "id": "openai/gpt-4o", "label": "GPT-4o", "type": "text" }
],
"video": [
{
"id": "seedance-2.0/text-to-video",
"label": "Seedance 2.0",
"tier": "premium",
"supports_audio": true,
"supports_lock_camera": true,
"durations": [4, 8, 12],
"cost_cents_per_5s": 300,
"type": "video",
"mode": "text-to-video",
"provider": "seedance"
}
],
"image": [
{ "id": "bytedance/seedream-4.5", "label": "Seedream 4.5", "type": "image" }
]
}
}生成视频
POST
/api/v1/video/generate提交异步视频生成任务。使用返回的 poll_url 轮询进度。
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Required | 模型 ID(如 "seedance-2.0/text-to-video") |
prompt | string | Required | 视频描述 |
duration | number | Optional | 时长秒数(默认 5,Seedance 支持 4/8/12) |
aspect_ratio | string | Optional | "16:9"、"9:16"、"1:1" 等(默认 "16:9") |
image_url | string | Optional | 图片 URL,用于图片转视频模型 |
generate_audio | boolean | Optional | 生成同步音频(Seedance 2.0, Wan 2.6) |
lock_camera | boolean | Optional | 锁定镜头(仅 Seedance 2.0) |
示例:
bashcurl -X POST https://xpilot.jytech.us/api/v1/video/generate \
-H "Authorization: Bearer xp_..." \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.0/text-to-video",
"prompt": "A cat walking on a beach at sunset",
"duration": 8,
"aspect_ratio": "16:9",
"generate_audio": true,
"lock_camera": false
}'响应:
json{
"task_id": "abc123",
"status": "processing",
"provider": "seedance",
"poll_url": "/api/v1/video/abc123?provider=seedance",
"cost_cents": 300,
"remaining_credits_cents": 4700
}查询视频状态
GET
/api/v1/video/:taskId查询视频生成状态。使用 generate 端点返回的 poll_url,每 3-5 秒轮询一次,直到 status 为 "completed" 或 "failed"。
| Parameter | Type | Required | Description |
|---|---|---|---|
provider | string | Optional | "wavespeed" 或 "seedance"(查询参数,默认 "wavespeed") |
pollUrl | string | Optional | Wavespeed 轮询 URL(查询参数,已包含在 poll_url 中) |
bash# Use the poll_url from the generate response
curl -H "Authorization: Bearer xp_..." \
"https://xpilot.jytech.us/api/v1/video/abc123?provider=seedance"响应(处理中):
json{
"task_id": "abc123",
"status": "processing",
"outputs": [],
"provider": "seedance"
}响应(已完成):
json{
"task_id": "abc123",
"status": "completed",
"outputs": ["https://cdn.example.com/video.mp4"],
"provider": "seedance"
}生成图片
POST
/api/v1/image/generate生成图片。部分模型同步返回结果,其余返回 poll_url 需轮询。
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Required | 模型 ID(如 "bytedance/seedream-4.5") |
prompt | string | Required | 图片描述 |
aspect_ratio | string | Optional | "1:1"、"16:9"、"9:16" 等 |
mode | string | Optional | "t2i"(文生图)、"i2i"(图生图)、"i2i_text"(图片文字编辑) |
image_url | string | Optional | 图片 URL,用于 i2i/编辑模式 |
image_urls | string[] | Optional | 多张参考图 URL |
bashcurl -X POST https://xpilot.jytech.us/api/v1/image/generate \
-H "Authorization: Bearer xp_..." \
-H "Content-Type: application/json" \
-d '{
"model": "bytedance/seedream-4.5",
"prompt": "A futuristic cityscape at dawn",
"aspect_ratio": "16:9"
}'响应(同步):
json{
"task_id": "img_456",
"status": "completed",
"outputs": ["https://cdn.example.com/image.png"],
"cost_cents": 5,
"remaining_credits_cents": 4695
}生成文字
POST
/api/v1/text/generate使用大语言模型生成文字,同步返回结果。
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Optional | 模型 ID(默认 "openai/gpt-4o") |
prompt | string | Required | 提示词 / 问题 |
system | string | Optional | 系统提示词 |
max_tokens | number | Optional | 最大输出 token 数(默认 1000) |
temperature | number | Optional | 采样温度 0-2(默认 0.7) |
bashcurl -X POST https://xpilot.jytech.us/api/v1/text/generate \
-H "Authorization: Bearer xp_..." \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o",
"prompt": "Write a tweet about AI video generation",
"max_tokens": 280
}'响应:
json{
"content": "AI video generation just hit a new level...",
"model": "openai/gpt-4o",
"usage": {
"prompt_tokens": 15,
"completion_tokens": 42,
"total_tokens": 57
},
"cost_cents": 1,
"remaining_credits_cents": 4694
}错误处理
所有错误返回包含 error 字段的 JSON 对象:
json{
"error": {
"message": "Invalid or missing API key",
"code": "UNAUTHORIZED"
}
}| HTTP | Code | 说明 |
|---|---|---|
| 400 | INVALID_PARAMS | 缺少或无效的请求参数 |
| 400 | INVALID_MODEL | 模型 ID 不存在 |
| 401 | UNAUTHORIZED | 缺少、无效或已撤销的 API Key |
| 402 | INSUFFICIENT_CREDITS | 余额不足 |
| 429 | RATE_LIMITED | 超过频率限制(30 请求/分钟),参考 Retry-After header |
| 500 | GENERATION_FAILED | 上游生成失败 |
完整示例:生成并下载视频
bash#!/bin/bash
API_KEY="xp_your_key_here"
HOST="https://xpilot.jytech.us"
# 1. Submit video generation
RESULT=$(curl -s -X POST "$HOST/api/v1/video/generate" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "seedance-2.0/text-to-video",
"prompt": "A golden retriever running through a meadow",
"duration": 8,
"generate_audio": true
}')
POLL_PATH=$(echo $RESULT | jq -r '.poll_url')
echo "Task submitted. Poll path: $POLL_PATH"
# 2. Poll until complete
while true; do
STATUS=$(curl -s -H "Authorization: Bearer $API_KEY" "$HOST$POLL_PATH")
STATE=$(echo $STATUS | jq -r '.status')
echo "Status: $STATE"
if [ "$STATE" = "completed" ]; then
VIDEO_URL=$(echo $STATUS | jq -r '.outputs[0]')
echo "Video ready: $VIDEO_URL"
curl -o output.mp4 "$VIDEO_URL"
break
elif [ "$STATE" = "failed" ]; then
echo "Error: $(echo $STATUS | jq -r '.error')"
break
fi
sleep 5
donePython 示例
pythonimport requests, time
API_KEY = "xp_your_key_here"
HOST = "https://xpilot.jytech.us"
HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
# Submit
resp = requests.post(f"{HOST}/api/v1/video/generate", headers=HEADERS, json={
"model": "seedance-2.0/text-to-video",
"prompt": "A cat walking on a beach at sunset",
"duration": 8,
"generate_audio": True,
})
data = resp.json()
poll_path = data["poll_url"]
print(f"Cost: {data['cost_cents']} cents | Credits left: {data['remaining_credits_cents']}")
# Poll
while True:
status = requests.get(f"{HOST}{poll_path}", headers=HEADERS).json()
print(f"Status: {status['status']}")
if status["status"] == "completed":
print(f"Video URL: {status['outputs'][0]}")
break
elif status["status"] == "failed":
print(f"Error: {status.get('error')}")
break
time.sleep(5)