xPilot API 文档

v1 REST API 参考

概述

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 轮询进度。

ParameterTypeRequiredDescription
modelstringRequired模型 ID(如 "seedance-2.0/text-to-video")
promptstringRequired视频描述
durationnumberOptional时长秒数(默认 5,Seedance 支持 4/8/12)
aspect_ratiostringOptional"16:9"、"9:16"、"1:1" 等(默认 "16:9")
image_urlstringOptional图片 URL,用于图片转视频模型
generate_audiobooleanOptional生成同步音频(Seedance 2.0, Wan 2.6)
lock_camerabooleanOptional锁定镜头(仅 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"。

ParameterTypeRequiredDescription
providerstringOptional"wavespeed" 或 "seedance"(查询参数,默认 "wavespeed")
pollUrlstringOptionalWavespeed 轮询 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 需轮询。

ParameterTypeRequiredDescription
modelstringRequired模型 ID(如 "bytedance/seedream-4.5")
promptstringRequired图片描述
aspect_ratiostringOptional"1:1"、"16:9"、"9:16" 等
modestringOptional"t2i"(文生图)、"i2i"(图生图)、"i2i_text"(图片文字编辑)
image_urlstringOptional图片 URL,用于 i2i/编辑模式
image_urlsstring[]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

使用大语言模型生成文字,同步返回结果。

ParameterTypeRequiredDescription
modelstringOptional模型 ID(默认 "openai/gpt-4o")
promptstringRequired提示词 / 问题
systemstringOptional系统提示词
max_tokensnumberOptional最大输出 token 数(默认 1000)
temperaturenumberOptional采样温度 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"
  }
}
HTTPCode说明
400INVALID_PARAMS缺少或无效的请求参数
400INVALID_MODEL模型 ID 不存在
401UNAUTHORIZED缺少、无效或已撤销的 API Key
402INSUFFICIENT_CREDITS余额不足
429RATE_LIMITED超过频率限制(30 请求/分钟),参考 Retry-After header
500GENERATION_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
done

Python 示例

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)
创建 API Key查看所有模型