{
  "openapi": "3.0.1",
  "info": {
    "title": "BibiGPT OpenAPI 规范",
    "description": "音视频 AI 学习助理的开放 API，加速音视频内容的信息提取，借助 AI 直接采取行动。",
    "version": "v1"
  },
  "servers": [
    {
      "url": "https://api.bibigpt.co"
    }
  ],
  "paths": {
    "/api/v1/audio/transcriptions": {
      "post": {
        "summary": "Transcribes an audio file into text.",
        "description": "Transcribes an audio file into text. Compatible with OpenAI Whisper API format.",
        "security": [
          {
            "ApiKeyAuth": []
          },
          {
            "OAuth2": ["read"]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  },
                  "language": {
                    "type": "string"
                  },
                  "timestamp_granularities": {
                    "type": "string"
                  },
                  "response_format": {
                    "type": "string",
                    "enum": ["text", "json", "verbose_json", "srt", "vtt"],
                    "description": "The format of the response."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The transcription result."
          },
          "400": {
            "description": "Bad request."
          },
          "401": {
            "description": "Unauthorized."
          },
          "500": {
            "description": "Internal server error."
          }
        }
      }
    },
    "/api/v1/chat/completions": {
      "post": {
        "summary": "Creates a summary completion for the given video url in chat message.",
        "description": "Support video_url type, or url in text content in chat message, another text content could be custom prompot for summary.. Compatible with OpenAI Chat API format.",
        "security": [
          {
            "ApiKeyAuth": []
          },
          {
            "OAuth2": ["read"]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["messages"],
                "properties": {
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": ["role", "content"],
                      "properties": {
                        "role": {
                          "type": "string",
                          "enum": ["system", "user", "assistant"],
                          "description": "The role of the message author"
                        },
                        "content": {
                          "oneOf": [
                            {
                              "type": "string",
                              "description": "Text content of the message. If it contains a video URL (e.g., https://www.bilibili.com/video/BV1Sk4y1x7r2), the video will be automatically summarized.",
                              "example": "https://www.bilibili.com/video/BV1Sk4y1x7r2"
                            },
                            {
                              "type": "object",
                              "properties": {
                                "text": {
                                  "type": "string",
                                  "description": "The text content to process. If it contains a video URL, the video will be automatically summarized. When used with video_url type in the same request, this text will be used as a custom summary prompt."
                                },
                                "type": {
                                  "type": "string",
                                  "enum": ["text"],
                                  "description": "Specifies this is a text content type"
                                }
                              },
                              "required": ["text", "type"],
                              "example": {
                                "text": "请帮我总结一下这个视频的内容，用中文回答",
                                "type": "text"
                              }
                            },
                            {
                              "type": "object",
                              "properties": {
                                "video_url": {
                                  "type": "string",
                                  "description": "The URL of the video to analyze (e.g., https://www.bilibili.com/video/BV1Sk4y1x7r2). Can be combined with a text message to customize the summary prompt."
                                },
                                "type": {
                                  "type": "string",
                                  "enum": ["video_url"],
                                  "description": "Explicitly specifies this is a video URL content type"
                                }
                              },
                              "required": ["video_url", "type"],
                              "example": {
                                "video_url": "https://www.bilibili.com/video/BV1Sk4y1x7r2",
                                "type": "video_url"
                              }
                            },
                            {
                              "type": "object",
                              "properties": {
                                "image_url": {
                                  "type": "string",
                                  "description": "The URL of the image to analyze"
                                },
                                "type": {
                                  "type": "string",
                                  "enum": ["image_url"],
                                  "description": "Specifies this is an image URL content type"
                                }
                              },
                              "required": ["image_url", "type"],
                              "example": {
                                "image_url": "https://example.com/image.jpg",
                                "type": "image_url"
                              }
                            }
                          ]
                        }
                      }
                    }
                  },
                  "model": {
                    "type": "string",
                    "description": "ID of the model to use. Defaults to 'bibigpt' if not specified. Can be prefixed with 'bibigpt/' for custom models."
                  },
                  "stream": {
                    "type": "boolean",
                    "description": "If set, partial message deltas will be sent as a stream.",
                    "default": false
                  }
                }
              },
              "example": {
                "messages": [
                  {
                    "role": "user",
                    "content": "https://www.bilibili.com/video/BV1Sk4y1x7r2"
                  }
                ],
                "model": "bibigpt",
                "stream": false
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response with completion",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Unique identifier for the completion"
                    },
                    "object": {
                      "type": "string",
                      "enum": ["chat.completion"]
                    },
                    "created": {
                      "type": "integer",
                      "description": "Unix timestamp of when the completion was created"
                    },
                    "model": {
                      "type": "string",
                      "description": "The model used for completion"
                    },
                    "choices": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "index": {
                            "type": "integer"
                          },
                          "message": {
                            "type": "object",
                            "properties": {
                              "role": {
                                "type": "string",
                                "enum": ["assistant"]
                              },
                              "content": {
                                "type": "string"
                              }
                            }
                          },
                          "finish_reason": {
                            "type": "string",
                            "enum": ["stop", "length", "content_filter"]
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - Invalid or missing API key",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded or insufficient credits",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "API Token for authentication. Use format 'Bearer YOUR_API_TOKEN'"
      },
      "OAuth2": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://api.bibigpt.co/api/auth/authorize",
            "tokenUrl": "https://api.bibigpt.co/api/auth/token",
            "scopes": {
              "read": "Read access to BibiGPT APIs",
              "write": "Write access to BibiGPT APIs"
            }
          }
        }
      }
    },
    "schemas": {
      "Organization": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "parent": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ChatSchema": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string"
          },
          "question": {
            "type": "string"
          },
          "history": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "nullable": true
          },
          "language": {
            "type": "string",
            "nullable": true
          },
          "includeDetail": {
            "type": "boolean",
            "nullable": true
          }
        }
      },
      "ExpressArticleSchema": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string"
          },
          "articleConfig": {
            "type": "object",
            "nullable": true,
            "properties": {
              "outputLanguage": {
                "type": "string",
                "nullable": true
              },
              "showEmoji": {
                "type": "boolean",
                "nullable": true
              },
              "isRefresh": {
                "type": "boolean",
                "nullable": true
              }
            }
          }
        }
      },
      "ReturnDetail": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string"
          },
          "descriptionText": {
            "type": "string"
          }
        }
      },
      "ApiTokenParams": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string"
          },
          "limitation": {
            "type": "object",
            "properties": {
              "maxDuration": {
                "type": "number",
                "format": "int64",
                "description": "in seconds"
              }
            }
          },
          "prompt": {
            "type": "string"
          },
          "promptConfig": {
            "type": "object",
            "properties": {
              "showEmoji:": {
                "type": "boolean"
              },
              "isRefresh": {
                "type": "boolean"
              },
              "sentenceNumber": {
                "type": "number"
              },
              "detailLevel": {
                "type": "number"
              },
              "outputLanguage": {
                "type": "string"
              }
            }
          },
          "includeDetail": {
            "type": "boolean"
          }
        }
      },
      "OpenAPISimpleSummaryResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "service": {
            "type": "string"
          },
          "sourceUrl": {
            "type": "string"
          },
          "htmlUrl": {
            "type": "string"
          },
          "costDuration": {
            "type": "number"
          },
          "remainingTime": {
            "type": "number"
          },
          "summary": {
            "type": "string"
          }
        }
      },
      "OpenAPISummaryResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "service": {
            "type": "string"
          },
          "sourceUrl": {
            "type": "string"
          },
          "htmlUrl": {
            "type": "string"
          },
          "costDuration": {
            "type": "number"
          },
          "remainingTime": {
            "type": "number"
          },
          "summary": {
            "type": "string"
          },
          "detail": {
            "$ref": "#/components/schemas/ReturnDetail"
          }
        }
      },
      "OpenAPIChatResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "service": {
            "type": "string"
          },
          "sourceUrl": {
            "type": "string"
          },
          "htmlUrl": {
            "type": "string"
          },
          "costDuration": {
            "type": "number"
          },
          "remainingTime": {
            "type": "number"
          },
          "answer": {
            "type": "string"
          },
          "sourceDocuments": {
            "type": "array",
            "items": {
              "properties": {
                "pageContent": {
                  "type": "string"
                },
                "metadata": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "OpenAPIExpressResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "service": {
            "type": "string"
          },
          "sourceUrl": {
            "type": "string"
          },
          "htmlUrl": {
            "type": "string"
          },
          "costDuration": {
            "type": "number"
          },
          "remainingTime": {
            "type": "number"
          },
          "article": {
            "type": "string"
          }
        }
      },
      "OpenAPIChapterSummaryResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "service": {
            "type": "string"
          },
          "sourceUrl": {
            "type": "string"
          },
          "htmlUrl": {
            "type": "string"
          },
          "costDuration": {
            "type": "number"
          },
          "remainingTime": {
            "type": "number"
          },
          "overallSummary": {
            "type": "string"
          },
          "overallTitle": {
            "type": "string"
          },
          "cover": {
            "type": "string"
          },
          "author": {
            "type": "string"
          },
          "chapters": {
            "type": "array",
            "items": {
              "properties": {
                "summary": {
                  "type": "string"
                },
                "title": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "tags": []
}
