{
  "openapi": "3.1.0",
  "info": {
    "title": "艾波开放平台 API",
    "version": "1.0.0",
    "description": "福建布波数字科技 · AI 工作台对外开放能力。\n\n鉴权：`Authorization: Bearer aibo_<40hex>`（后台自助签发，明文只显示一次，服务端只存 sha256）。\n\n计费：按调用扣算力（当前 chat=1、tts=1）；**失败自动退回**，通道不可用直接 503 且不扣算力。\n\n人看的文档：https://ai.aibobos.com/openapi/",
    "contact": {
      "name": "福建布波数字科技",
      "url": "https://ai.aibobos.com"
    },
    "x-generated-at": "2026-09-26"
  },
  "servers": [
    {
      "url": "https://ai.aibobos.com/api/openapi/v1",
      "description": "生产环境"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer aibo_<40位十六进制>；能力域见文档"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              },
              "type": {
                "type": "string"
              },
              "code": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "openapi",
      "description": "对外开放端点（API Key 鉴权）"
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "tags": [
          "openapi"
        ],
        "summary": "归属与用量",
        "description": "查这枚 Key 属于谁、开通了哪些能力、累计调用与消耗。Agent 接入后的第一条自检调用。\n\n为什么需要：Agent 自检：确认 Key 有效、能力域够用、余额有余量，再决定后续动作。",
        "operationId": "me",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "ok": 1,
                  "key_name": "波哥实测",
                  "masked": "aibo_349e68a***",
                  "scopes": [
                    "chat",
                    "tts",
                    "records"
                  ],
                  "use_count": 88,
                  "expires_at": 0,
                  "stats": {
                    "calls": 88,
                    "cost": 13,
                    "ok_calls": 13
                  }
                }
              }
            }
          },
          "401": {
            "description": "Key 缺失 / 无效 / 吊销 / 过期 / 缺能力域"
          },
          "402": {
            "description": "算力不足（无交付、不计费）"
          },
          "500": {
            "description": "上游异常（已退回算力）"
          }
        }
      }
    },
    "/models": {
      "get": {
        "tags": [
          "openapi"
        ],
        "summary": "模型列表",
        "description": "OpenAI 兼容的模型列表。当前两个：`aibo-chat`（对话）、`aibo-agent`（Agent 编排，同一条链路）。\n\n为什么需要：任何 OpenAI 客户端接入前都会先拉这个端点，返回标准结构即可被自动识别。\n\n所需能力域：`chat`",
        "operationId": "models",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "list",
                  "data": [
                    {
                      "id": "aibo-chat",
                      "object": "model",
                      "created": 1790114860,
                      "owned_by": "aibobos"
                    },
                    {
                      "id": "aibo-agent",
                      "object": "model",
                      "created": 1790114860,
                      "owned_by": "aibobos"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Key 缺失 / 无效 / 吊销 / 过期 / 缺能力域"
          },
          "402": {
            "description": "算力不足（无交付、不计费）"
          },
          "500": {
            "description": "上游异常（已退回算力）"
          }
        }
      }
    },
    "/chat/completions": {
      "post": {
        "tags": [
          "openapi"
        ],
        "summary": "对话（OpenAI 兼容）",
        "description": "标准 OpenAI Chat Completions。**内置能力编排**：识别到配音/朗读类指令时自动改走配音链路并返回音频地址。\n\n为什么需要：这条能通，意味着 Cursor / Codex / Cherry Studio / 任意 OpenAI SDK 都能直接接进来，零改造。\n\n所需能力域：`chat`",
        "operationId": "chat_completions",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "id": "chatcmpl-3f2a9c1b8d4e5f60718293a4",
                  "object": "chat.completion",
                  "created": 1790114860,
                  "model": "aibo-chat",
                  "choices": [
                    {
                      "index": 0,
                      "message": {
                        "role": "assistant",
                        "content": "AI Agent 是一种能够自主感知环境、推理决策并采取行动以实现特定目标的智能系统。"
                      },
                      "finish_reason": "stop"
                    }
                  ],
                  "usage": {
                    "prompt_tokens": 15,
                    "completion_tokens": 41,
                    "total_tokens": 56
                  }
                }
              }
            }
          },
          "401": {
            "description": "Key 缺失 / 无效 / 吊销 / 过期 / 缺能力域"
          },
          "402": {
            "description": "算力不足（无交付、不计费）"
          },
          "500": {
            "description": "上游异常（已退回算力）"
          },
          "400": {
            "description": "messages 不能为空 / 未找到有效的 user 消息"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "`aibo-chat` 或 `aibo-agent`；仅记录在响应里，不影响实际链路。"
                  },
                  "messages": {
                    "type": "array",
                    "description": "OpenAI 标准消息数组；**取最后一条 `role=user` 的内容**作为本次指令。"
                  },
                  "stream": {
                    "type": "boolean",
                    "description": "当前只支持 `false`（非流式）。传 `true` 会按非流式返回。"
                  }
                },
                "required": [
                  "model",
                  "messages"
                ]
              },
              "example": {
                "model": "aibo-chat",
                "messages": [
                  {
                    "role": "user",
                    "content": "用一句话说明什么是 AI Agent"
                  }
                ]
              }
            }
          }
        }
      }
    },
    "/voices": {
      "get": {
        "tags": [
          "openapi"
        ],
        "summary": "可用音色",
        "description": "列出当前账号可用的音色（公共音色 + 自己克隆的），并给出默认音色。\n\n为什么需要：Agent 不必让人先挑音色——不传 `voice_id` 时服务端会自动取列表第一个。\n\n所需能力域：`tts`",
        "operationId": "voices",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "list",
                  "data": [
                    {
                      "voice_id": "vox_demo_public",
                      "name": "演示公共音色",
                      "gender": "female",
                      "language": "zh",
                      "source": "public"
                    }
                  ],
                  "default": "vox_demo_public"
                }
              }
            }
          },
          "401": {
            "description": "Key 缺失 / 无效 / 吊销 / 过期 / 缺能力域"
          },
          "402": {
            "description": "算力不足（无交付、不计费）"
          },
          "500": {
            "description": "上游异常（已退回算力）"
          }
        }
      }
    },
    "/tts": {
      "post": {
        "tags": [
          "openapi"
        ],
        "summary": "生成配音",
        "description": "文本转语音。**同步优先**：站点语音通道直接出音频就返回 `audio_url`；不可用则转异步任务返回 `id`，用 `/task` 轮询。\n\n为什么需要：这是「一句话出音频」的落点。设计上前置校验通道可用性——**不可用当场拒绝且不扣费**，不做假交付。\n\n所需能力域：`tts`",
        "operationId": "tts",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "ok": 1,
                  "mode": "sync",
                  "audio_url": "https://ai.aibobos.com/uploads/.../xxx.mp3",
                  "chars": 20,
                  "cost": 1
                }
              }
            }
          },
          "401": {
            "description": "Key 缺失 / 无效 / 吊销 / 过期 / 缺能力域"
          },
          "402": {
            "description": "算力不足（无交付、不计费）"
          },
          "500": {
            "description": "上游异常（已退回算力）"
          },
          "503": {
            "description": "配音通道未就绪（未扣算力）"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "text": {
                    "type": "string",
                    "description": "要合成的文本，上限由站点配置 `tts_max_chars` 决定（当前 1000 字）。"
                  },
                  "voice_id": {
                    "type": "string",
                    "description": "留空则自动取 `/voices` 的第一个音色。"
                  },
                  "speed": {
                    "type": "string",
                    "description": "语速，默认 `\"1.0\"`。"
                  }
                },
                "required": [
                  "text"
                ]
              },
              "example": {
                "text": "艾波开放平台已支持 OpenAI 兼容调用。",
                "voice_id": "",
                "speed": "1.0"
              }
            }
          }
        }
      }
    },
    "/task": {
      "get": {
        "tags": [
          "openapi"
        ],
        "summary": "查询配音任务",
        "description": "按 `id` 查异步配音任务状态。轮询到 `status=2` 即完成，取 `audio_url`。\n\n为什么需要：异步交付的收口端点；没有它，Agent 拿不到成片链接。\n\n所需能力域：`tts`",
        "operationId": "task",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "ok": 1,
                  "data": {
                    "id": 123,
                    "status": 2,
                    "status_text": "已完成",
                    "text": "艾波开放平台已支持 OpenAI 兼容调用。",
                    "chars": 20,
                    "audio_url": "https://ai.aibobos.com/uploads/.../xxx.mp3"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Key 缺失 / 无效 / 吊销 / 过期 / 缺能力域"
          },
          "402": {
            "description": "算力不足（无交付、不计费）"
          },
          "500": {
            "description": "上游异常（已退回算力）"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "`/tts` 异步返回的 `id`。仅能查自己账号的任务。",
            "schema": {
              "type": "integer"
            }
          }
        ]
      }
    },
    "/records": {
      "get": {
        "tags": [
          "openapi"
        ],
        "summary": "调用记录",
        "description": "当前账号的配音记录列表（倒序），含状态、文案、字数、音频地址与真实时间戳。\n\n为什么需要：给 Agent 做「上次那条音频在哪」的取回能力，不必让用户翻后台。\n\n所需能力域：`records`",
        "operationId": "records",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                },
                "example": {
                  "object": "list",
                  "count": 2,
                  "data": [
                    {
                      "id": 123,
                      "status": 2,
                      "status_text": "已完成",
                      "text": "艾波开放平台已支持 OpenAI 兼容调用。",
                      "chars": 20,
                      "audio_url": "https://ai.aibobos.com/uploads/.../xxx.mp3",
                      "create_time": 1790114860
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Key 缺失 / 无效 / 吊销 / 过期 / 缺能力域"
          },
          "402": {
            "description": "算力不足（无交付、不计费）"
          },
          "500": {
            "description": "上游异常（已退回算力）"
          }
        }
      }
    }
  }
}