开放 API

开放 API

把 Piccc AI 的对话、图片生成和视频生成能力接入你的应用、自动化脚本或业务系统。对话接口支持常见 SDK 接入方式;图片和视频任务可通过轮询查询结果,也可以接收 WebHook 回调。

快速开始

1. 创建 API Key

在 ApiKey 页创建密钥,并保存在服务端环境变量中。请不要把密钥放进前端代码、公开仓库或客户端安装包。

2. 选择公开模型名

对话接口可使用 piccc-flash、piccc-pro、piccc-ultra。根据延迟、质量和任务复杂度选择合适模型。

3. 轮询或等待回调

图片和视频生成会返回任务 ID。你的服务可以定时查询任务状态,也可以配置 HTTPS WebHook 接收完成通知。

鉴权

所有请求都需要携带 API Key。推荐使用 Authorization 请求头;也可以使用 X-API-Key 请求头。密钥只会在创建时显示一次,请妥善保存。

Authorization: Bearer pcc_live_xxxxxxxxxxxxxxxxxxxxxxxx

对话模型 API

如果你的应用已经使用 OpenAI 或 Anthropic SDK,通常只需要调整 base URL、模型名和 API Key。需要实时展示生成内容时,可以开启 stream。

OpenAI 兼容示例

curl https://api.example.com/v1/chat/completions \
  -H "Authorization: Bearer $PICCC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "piccc-pro",
    "messages": [{"role":"user","content":"Write a launch caption."}],
    "stream": false
  }'

Anthropic 兼容示例

curl https://api.example.com/v1/messages \
  -H "Authorization: Bearer $PICCC_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "piccc-pro",
    "max_tokens": 512,
    "messages": [{"role":"user","content":"Write a launch caption."}]
  }'

图片和视频任务

提交提示词、模型和尺寸等参数后,接口会返回 task_id、status 和 polling_url。生成过程不需要保持 HTTP 连接,适合在后端服务或自动化流程中调用。

curl https://api.example.com/v1/images/tasks \
  -H "Authorization: Bearer $PICCC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "image-model-id",
    "prompt": "A clean product hero image for a ceramic mug",
    "aspect_ratio": "1:1",
    "resolution": "1K",
    "webhook": {"url": "https://your.app/piccc/webhook"}
  }'
curl https://api.example.com/v1/videos/tasks \
  -H "Authorization: Bearer $PICCC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "video-model-id",
    "prompt": "A 6 second product reveal video",
    "resolution": "720p",
    "aspect_ratio": "16:9",
    "duration_seconds": 6,
    "webhook": {"url": "https://your.app/piccc/webhook"}
  }'

任务查询 API

使用 GET /v1/tasks/{task_id} 查询单个任务;也可以使用 GET /v1/tasks 按 type/status 分页查询任务列表。建议轮询间隔保持在 2 到 5 秒。

curl https://api.example.com/v1/tasks/task_xxx \
  -H "Authorization: Bearer $PICCC_API_KEY"