LogoHappyHorse 文档
LogoHappyHorse 文档
首页

开始

快速开始生成工作台

创作

提示词和参考素材提示词模板风格和镜头输出质量

运营

积分、套餐和发布安全和账号限制

集成

客户 API产品概览

客户 API

使用 HappyHorse API 创建视频、上传参考素材并轮询生成状态。

可用状态

HappyHorse Customer API 已通过 /api/v1 向客户集成开放。当你的工作区已启用 API Key 后,即可使用 Customer API。如果你看不到 API Keys 页面,请联系 HappyHorse 管理员或支持人员。

启用访问后,登录用户可以在 Dashboard / Settings / API Keys 创建和管理密钥。 创建密钥后,请复制仅显示一次的完整 secret,安全保存,并删除不再使用的密钥。

所有请求都使用 Bearer Token:

Authorization: Bearer hh_live_your_api_key

基础 URL

请使用你的 HappyHorse 生产域名作为基础 URL:

https://<your-happyhorse-domain>

下面的示例默认你已经设置:

export HAPPYHORSE_API_KEY="hh_live_your_api_key"
export HAPPYHORSE_BASE_URL="https://<your-happyhorse-domain>"

认证方式

每个 Customer API endpoint 都需要 Authorization header。缺少、无效或被限流 的密钥会返回下文定义的稳定错误格式。

curl "$HAPPYHORSE_BASE_URL/api/v1/videos/example-id" \
  -H "Authorization: Bearer $HAPPYHORSE_API_KEY"

上传参考素材

POST /api/v1/uploads/presign 用于为视频参考素材创建短期有效的上传 URL。 接口会返回一个 storage key;创建视频时把这个 key 传给 POST /api/v1/videos。

HappyHorse 当前支持客户直接上传以下素材:

类型Content types最大大小
imageimage/png, image/jpeg, image/webp10 MB
videovideo/mp4, video/quicktime, video/webm50 MB
audioaudio/mpeg, audio/mp3, audio/wav, audio/webm15 MB

如果录音工具导出的是 audio/mp4,请先转换为当前接受的音频 MIME 类型再上传。 当前 API 会对不支持的类型返回 upload_type_not_supported。

请求

{
  "kind": "image",
  "contentType": "image/png",
  "sizeBytes": 5242880
}

kind 可省略,默认是 image。sizeBytes 必须是即将上传文件的准确大小。

响应

{
  "uploadUrl": "https://storage.example.com/presigned-url",
  "key": "videos/inputs/user-id/asset-id.png",
  "publicUrl": "https://cdn.example.com/videos/inputs/user-id/asset-id.png",
  "kind": "image"
}

你可以先创建 presign 并保存响应,再从响应里取出 uploadUrl 和 key,最后用 相同的 content type 和文件大小上传文件:

curl -X POST "$HAPPYHORSE_BASE_URL/api/v1/uploads/presign" \
  -H "Authorization: Bearer $HAPPYHORSE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "image",
    "contentType": "image/png",
    "sizeBytes": 5242880
  }' > presign.json

UPLOAD_URL="$(jq -r '.uploadUrl' presign.json)"
SOURCE_IMAGE_KEY="$(jq -r '.key' presign.json)"

curl -X PUT "$UPLOAD_URL" \
  -H "Content-Type: image/png" \
  --data-binary "@reference.png"

创建视频时,把 SOURCE_IMAGE_KEY 作为 sourceImageKey。如果上传的是参考视频或 音频,则把取出的 key 作为 referenceVideoKey 或 referenceAudioKey。

常见错误包括 invalid_input、upload_file_too_large、 upload_type_not_supported、missing_api_key、invalid_api_key、 rate_limited 和 internal_error。

创建视频

POST /api/v1/videos 会启动一个异步视频生成任务。接口会立即扣除积分、把任务 加入队列,并返回视频 ID。请轮询 GET /api/v1/videos/{id},直到状态变为 ready 或 failed。

模型由客户当前套餐自动选择。当前 API 不接受 model 字段。

请求

{
  "prompt": "A cinematic shot of a chestnut horse running through a sunlit meadow",
  "style": "cinematic",
  "durationSec": 6,
  "aspectRatio": "16:9",
  "resolution": "720p",
  "sourceImageKey": "videos/inputs/user-id/asset-id.png",
  "referenceVideoKey": "videos/reference-video/user-id/clip-id.mp4",
  "referenceAudioKey": "videos/reference-audio/user-id/audio-id.mp3",
  "cameraMotion": "pan-right",
  "motionIntensity": 3,
  "cfgScale": 0.5
}

支持字段:

字段类型说明
promptstring必填,3 到 2000 个字符。
stylestring可选,最多 50 个字符。
durationSecinteger必填,3 到 12 秒。套餐限制会生效。
aspectRatioenum可选,默认 16:9。可选值:16:9、9:16、1:1。
resolutionenum可选,默认 720p。可选值:720p、1080p。
sourceImageKeystring可选,上传预签接口返回的首帧/参考图片 key。
lastFrameKeystring可选,尾帧图片 key。不能与 sourceImageKey 同时使用。
referenceVideoKeystring可选,上传预签接口返回的参考视频 key。
referenceAudioKeystring可选,上传预签接口返回的参考音频 key。
cameraMotionenum可选,默认 none。可选值:none、static、pan-left、pan-right、tilt-up、tilt-down、zoom-in、zoom-out、orbit。
motionIntensityinteger可选,1 到 5。
cfgScalenumber可选,0 到 1。

当前 API 使用 HappyHorse storage key 作为输入素材引用,不接受任意外部 inputImageUrl、referenceVideoUrl 或 audioUrl 字段。请先调用 POST /api/v1/uploads/presign,上传素材,再传入响应中的 key。

响应

{
  "id": "018f3f1d-8c2e-7b4d-9db1-8e8f3a0c8f21",
  "status": "queued"
}

示例:

curl -X POST "$HAPPYHORSE_BASE_URL/api/v1/videos" \
  -H "Authorization: Bearer $HAPPYHORSE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "A cinematic shot of a chestnut horse running through a sunlit meadow",
    "style": "cinematic",
    "durationSec": 6,
    "aspectRatio": "16:9",
    "resolution": "720p"
  }'

积分和套餐错误:

  • insufficient_credits,HTTP 402,表示账号积分不足,无法支付当前时长和清晰度。
  • plan_gate_exceeded,HTTP 403,表示当前套餐不允许某个设置,例如时长、参考音频、 尾帧输入或其他受限功能。响应会包含 field、requiredPlan 和 currentPlan。

查询视频状态

GET /api/v1/videos/{id} 返回单个视频的当前状态。API Key 只能读取该密钥所属 用户创建的视频。其他账号的视频会返回 not_found。

curl "$HAPPYHORSE_BASE_URL/api/v1/videos/018f3f1d-8c2e-7b4d-9db1-8e8f3a0c8f21" \
  -H "Authorization: Bearer $HAPPYHORSE_API_KEY"

响应:

{
  "id": "018f3f1d-8c2e-7b4d-9db1-8e8f3a0c8f21",
  "status": "ready",
  "prompt": "A cinematic shot of a chestnut horse running through a sunlit meadow",
  "style": "cinematic",
  "durationSec": 6,
  "aspectRatio": "16:9",
  "resolution": "720p",
  "videoUrl": "https://cdn.example.com/videos/outputs/018f3f1d.mp4",
  "thumbnailUrl": null,
  "errorMessage": null,
  "readyAt": "2026-04-26T12:30:00.000Z"
}

常见状态包括 queued、processing、ready 和 failed。在素材生成前, videoUrl 和 thumbnailUrl 为 null。如果生成失败,status 会变为 failed,errorMessage 会描述失败原因。

错误格式

Customer API 错误使用稳定 JSON envelope:

{
  "error": {
    "code": "invalid_input",
    "message": "Request body is invalid."
  }
}

部分错误会包含额外字段:

{
  "error": {
    "code": "plan_gate_exceeded",
    "message": "Your plan does not allow this video setting.",
    "field": "referenceAudio",
    "requiredPlan": "pro",
    "currentPlan": "basic"
  }
}

主要错误码:

CodeHTTP含义
missing_api_key401未提供 Bearer token。
invalid_api_key401token 缺失、已删除、格式错误或无效。
rate_limited429API Key 超出限流。
invalid_input400JSON body 或路由输入未通过校验。
insufficient_credits402账号积分不足。
plan_gate_exceeded403当前套餐不允许请求的设置。
upload_file_too_large413上传文件超过对应类型的最大大小。
upload_type_not_supported400当前上传类型不接受该 MIME 类型。
not_found404视频不存在,或不属于当前 API Key 所属账号。
internal_error500HappyHorse 无法完成请求。

Webhook

HappyHorse 目前还没有面向客户的视频状态 webhook endpoint。集成方应轮询 GET /api/v1/videos/{id},直到状态变为 ready 或 failed。大多数任务可以 使用 5 到 10 秒的轮询间隔。

安全和账号限制

HappyHorse 如何保护生成资源并处理滥用防护。

产品概览

HappyHorse 如何进入创作者、营销和产品团队的工作流。

目录

可用状态
基础 URL
认证方式
上传参考素材
请求
响应
创建视频
请求
响应
查询视频状态
错误格式
Webhook