模型 API 目录(含官方/标准)▾
图像系列
视频系列

[官方] = 官方上游渠道;[标准] = 经济路由。同族可展开切换对比。

SDK 示例 // EXAMPLES

Python(requests)
import requests, time

BASE = "https://xiaoguai123.xyz"
KEY = "cr_你的Key"
H = {"Authorization": f"Bearer {KEY}"}

# 生图
r = requests.post(
    f"{BASE}/api/v1/images/generations",
    headers=H,
    json={"model": "gpt-image-2", "prompt": "霓虹灯下的猫", "size": "1:1", "resolution": "1K"},
)
r.raise_for_status()
task_id = r.json()["data"][0]["task_id"]
print("task:", task_id)

while True:
    t = requests.get(f"{BASE}/api/v1/tasks/{task_id}", headers=H).json()["data"]
    print(t["status"], t.get("progress"))
    if t["status"] in ("completed", "failed"):
        print(t)
        break
    time.sleep(3)
JavaScript(fetch)
const BASE = "https://xiaoguai123.xyz";
const KEY = "cr_你的Key";

async function generate() {
  const submit = await fetch(BASE + "/api/v1/images/generations", {
    method: "POST",
    headers: {
      Authorization: "Bearer " + KEY,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "gpt-image-2",
      prompt: "霓虹灯下的猫",
      size: "1:1",
      resolution: "1K",
    }),
  }).then((r) => r.json());

  const taskId = submit.data[0].task_id;
  for (;;) {
    const t = await fetch(BASE + "/api/v1/tasks/" + taskId, {
      headers: { Authorization: "Bearer " + KEY },
    }).then((r) => r.json());
    if (["completed", "failed"].includes(t.data.status)) return t.data;
    await new Promise((r) => setTimeout(r, 3000));
  }
}

generate().then(console.log);