EN

API 开发文档

开放 REST API,使用 API 密钥鉴权,按模型单价扣除算力。

鉴权说明

所有接口需在 HTTP Header 中携带密钥:

Authorization: Bearer xf_你的API密钥

密钥在登录后 用户中心 → API 密钥 创建。每次调用按对应模型单价扣除算力,算力不足返回错误。

基础地址:https://ai.xffuw.com/api/v1/

1. 获取模型列表

GETmodels.php

https://ai.xffuw.com/api/v1/models.php

返回已上架模型 slug、名称、类型、单价等。

{

  "data": [

    {

      "slug": "gpt-4o-mini",

      "name": "GPT-4o Mini",

      "type": "chat",

      "price": "0.5000",

      "description": "..."

    }

  ]

}

2. 对话补全

POSTchat.php

POST https://ai.xffuw.com/api/v1/chat.php

Content-Type: application/json

Authorization: Bearer xf_xxx



{

  "model": "gpt-4o-mini",

  "messages": [

    {"role": "user", "content": "你好,介绍一下你自己"}

  ]

}
字段类型说明
modelstring模型 slug,见模型列表
messagesarrayOpenAI 格式消息数组,支持多轮

成功响应:

{

  "choices": [

    {"message": {"content": "你好!我是 AI 助手..."}}

  ]

}

3. 图像 / 媒体生成

POSTimage.php

POST https://ai.xffuw.com/api/v1/image.php

Content-Type: application/json

Authorization: Bearer xf_xxx



{

  "model": "gpt-image-2",

  "prompt": "一只可爱的橘猫,高清摄影",

  "images": ["https://你的域名/uploads/ref.jpg"]

}
字段类型说明
modelstring图像模型 slug
promptstring提示词
imagesarray可选,参考图 URL 数组(图生图)

异步任务响应(需轮询):

{"ok": true, "task_id": "123456789", "type": "image"}

即时返回(部分模型):

{"ok": true, "result_url": "https://...", "type": "image"}

4. 查询生成任务

GETtask.php

GET https://ai.xffuw.com/api/v1/task.php?task_id=123456789

返回统一格式:

{

  "is_final": true,

  "state": "success",

  "result_url": "https://cdn.example.com/image.png",

  "media_type": "image",

  "progress": ""

}
  • state:pending / running / success / failed
  • is_final:true 表示任务结束
  • result_url:成功时的图片/视频/音频地址

建议每 2~4 秒轮询一次,直到 is_final=true 或拿到 result_url

错误响应

{"error": "invalid api key"}

{"error": "insufficient balance"}

{"error": "model not found"}

调用示例(cURL)

curl -X POST "https://ai.xffuw.com/api/v1/chat.php" \

  -H "Authorization: Bearer xf_你的密钥" \

  -H "Content-Type: application/json" \

  -d "{\"model\":\"gpt-4o-mini\",\"messages\":[{\"role\":\"user\",\"content\":\"hi\"}]}"

创建 API 密钥 查看模型价格