# 计算价格/Calculate price

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /api/v1/tikhub/user/calculate_price:
    get:
      summary: 计算价格/Calculate price
      deprecated: false
      description: >-
        # [中文]

        ### 用途:

        - 根据用户输入的每日请求次数以及端点信息计算最终价格。

        ### 参数:

        - endpoint: 请求的端点，用于查询端点的原始请求单价

        - request_per_day: 每日请求次数，用于计算价格，将自动根据阶梯式计费的折扣百分比计算最终价格

        ### 计算公式:

        - 总成本 = ∑ (阶梯内请求次数 * 阶梯折后单价)

        - 其中，阶梯折后单价 = 基础价格 * (1 - 折扣)

        ### 详细计算步骤:

        1. **初始化总成本**：
           总成本=0
        2. **遍历每个阶梯**：
           * 对于每个阶梯，计算该阶梯内的请求次数。
           * 计算该阶梯内的折后单价。
           * 计算该阶梯内的总费用，并累加到总成本中。
           * 更新剩余的请求次数。
        ### 数学表示:

        > 设有 𝑛 个阶梯，每个阶梯的参数为：

        * min_rpd𝑖: 第 𝑖 个阶梯的最小请求次数

        * max_rpd𝑖: 第 𝑖 个阶梯的最大请求次数

        * discount𝑖: 第 𝑖 个阶梯的折扣（百分比形式）

        * base_price：基础价格

        * request_per_day：每日请求次数

        > 那么，总成本的计算公式如下：

        - 总成本 = Σ𝑖=1𝑛（阶梯𝑖中的请求数量 * 阶梯𝑖中的折扣单价）

        - 其中，阶梯折扣单价 𝑖 = base_price * (1 - 折扣𝑖/100)

        - 该阶梯中的请求数 𝑖 = min(request_per_day - 累计付费请求数, max_rpd𝑖 - min_rpd𝑖)

        ### 示例

        > 假设有以下定价阶梯：

        * 第 1 阶梯：0 ≤ rpd < 1000，折扣 0%

        * 第 2 阶梯：1000 ≤ rpd < 5000，折扣 10%

        * 第 3 阶梯：5000 ≤ rpd < 10000，折扣 20%

        * 第 4 阶梯：10000 ≤ rpd < 20000，折扣 30%

        * 第 5 阶梯：20000 ≤ rpd < 30000，折扣 40%

        * 第 6 阶梯：30000 ≤ rpd，折扣 50%

        > 假设基础价格为 0.001 USD，每日请求次数为 12000，则计算过程如下：

        1. **第 1 阶梯**（0 ≤ rpd < 1000）：
           * 阶梯内请求次数=1000−0=1000
           * 阶梯折后单价=0.001×(1−0/100)=0.001
           * 总成本=1000×0.001=1
        2. **第 2 阶梯**（1000 ≤ rpd < 5000）：
           * 阶梯内请求次数=5000−1000=4000
           * 阶梯折后单价=0.001×(1−10/100)=0.0009
           * 总成本=4000×0.0009=3.6
        3. **第 3 阶梯**（5000 ≤ rpd < 10000）：
           * 阶梯内请求次数=10000−5000=5000
           * 阶梯折后单价=0.001×(1−20/100)=0.0008
           * 总成本=5000×0.0008=4
        4. **第 4 阶梯**（10000 ≤ rpd < 20000）：
           * 阶梯内请求次数=12000−10000=2000
           * 阶梯折后单价=0.001×(1−30/100)=0.0007
           * 总成本=2000×0.0007=1.4
        5. **累加总成本**：
           * 总成本=1+3.6+4+1.4=10
        ### 返回:

        - 端点uri

        - 每日请求次数

        - 端点原始请求单价

        - 总价格

        - 货币单位

        - 阶梯式计费的折扣百分比信息


        # [English]

        ### Purpose:

        - Calculate the final price based on the user's input of the number of
        daily requests and endpoint information.

        - Price calculation formula: Price = Number of daily requests *
        (Original request unit price of the endpoint * (1 - discount percentage
        of tiered billing))

        ### Parameters:

        - endpoint: Requested endpoint, used to query the original request unit
        price of the endpoint

        - request_per_day: Number of daily requests, used to calculate the
        price, the final price will be calculated automatically based on the
        discount percentage of the tiered billing

        ### Calculation formula:

        - Total cost = ∑ (Number of requests in the tier * Discounted unit price
        in the tier)

        - Where, Discounted unit price in the tier = Base price * (1 - Discount)

        ### Detailed calculation steps:

        1. **Initialize the total cost**:
             Total cost = 0
        2. **Traverse each tier**:
                * For each tier, calculate the number of requests in the tier.
                * Calculate the discounted unit price in the tier.
                * Calculate the total cost in the tier and add it to the total cost.
                * Update the remaining number of requests.
        ### Mathematical representation:

        Suppose there are 𝑛 tiers, and the parameters of each tier are:

        * min_rpd𝑖: The minimum number of requests in the 𝑖-th tier

        * max_rpd𝑖: The maximum number of requests in the 𝑖-th tier

        * discount𝑖: The discount of the 𝑖-th tier (in percentage form)

        * base_price: Base price

        * request_per_day: Number of daily requests

        > Then, the formula for calculating the total cost is as follows:

        - Total cost = ∑𝑖=1𝑛(Number of requests in the tier 𝑖 * Discounted
        unit price in the tier 𝑖)

        - Where, Discounted unit price in the tier 𝑖 = base_price * (1 -
        discount𝑖/100)

        - Number of requests in the tier 𝑖 = min(request_per_day - accumulated
        number of paid requests, max_rpd𝑖 - min_rpd𝑖)

        ### Example

        Suppose there are the following pricing tiers:

        * Tier 1: 0 ≤ rpd < 1000, discount 0%

        * Tier 2: 1000 ≤ rpd < 5000, discount 10%

        * Tier 3: 5000 ≤ rpd < 10000, discount 20%

        * Tier 4: 10000 ≤ rpd < 20000, discount 30%

        * Tier 5: 20000 ≤ rpd < 30000, discount 40%

        * Tier 6: 30000 ≤ rpd, discount 50%

        > Suppose the base price is 0.001 USD and the number of daily requests
        is 12000, the calculation process is as follows:

        1. **Tier 1** (0 ≤ rpd < 1000):
             - Number of requests in the tier 1 = 1000 - 0 = 1000
             - Discounted unit price in the tier 1 = 0.001 * (1 - 0/100) = 0.001
             - Total cost 1 = 1000 * 0.001 = 1
        2. **Tier 2** (1000 ≤ rpd < 5000):
            - Number of requests in the tier 2 = 5000 - 1000 = 4000
            - Discounted unit price in the tier 2 = 0.001 * (1 - 10/100) = 0.0009
            - Total cost 2 = 4000 * 0.0009 = 3.6
        3. **Tier 3** (5000 ≤ rpd < 10000):
            - Number of requests in the tier 3 = 10000 - 5000 = 5000
            - Discounted unit price in the tier 3 = 0.001 * (1 - 20/100) = 0.0008
            - Total cost 3 = 5000 * 0.0008 = 4
        4. **Tier 4** (10000 ≤ rpd < 20000):
            - Number of requests in the tier 4 = 12000 - 10000 = 2000
            - Discounted unit price in the tier 4 = 0.001 * (1 - 30/100) = 0.0007
            - Total cost 4 = 2000 * 0.0007 = 1.4
        5. **Accumulated total cost**:
            - Total cost = 1 + 3.6 + 4 + 1.4 = 10
        ### Return:

        - Endpoint uri

        - Number of daily requests

        - Original request unit price of the endpoint

        - Total price

        - Currency unit

        - Discount percentage information of tiered billing
      operationId: calculate_price_api_v1_tikhub_user_calculate_price_get
      tags:
        - TikHub-User-API
        - TikHub-User-API
      parameters:
        - name: endpoint
          in: query
          description: 请求的端点/Requested endpoint
          required: true
          example: /api/v1/douyin/app/v1/fetch_one_video
          schema:
            type: string
            description: 请求的端点/Requested endpoint
            title: Endpoint
        - name: request_per_day
          in: query
          description: 每日请求次数/Request per day
          required: false
          example: 100000
          schema:
            type: integer
            description: 每日请求次数/Request per day
            default: 1
            title: Request Per Day
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ResponseModel'
          headers: {}
          x-apifox-name: OK
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          headers: {}
          x-apifox-name: Unprocessable Entity
      security:
        - HTTPBearer: []
          x-apifox:
            schemeGroups:
              - id: XQ_zU69LiL9WeZqX_KnZD
                schemeIds:
                  - HTTPBearer
            required: true
            use:
              id: XQ_zU69LiL9WeZqX_KnZD
            scopes:
              XQ_zU69LiL9WeZqX_KnZD:
                HTTPBearer: []
      x-apifox-folder: TikHub-User-API
      x-apifox-status: released
      x-run-in-apifox: https://app.apifox.com/web/project/4705614/apis/api-186826052-run
components:
  schemas:
    ResponseModel:
      properties:
        code:
          type: integer
          title: Code
          description: HTTP status code | HTTP状态码
          default: 200
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Request Id
          description: Unique request identifier | 唯一请求标识符
        message:
          type: string
          title: Message
          description: Response message (EN-US) | 响应消息 (English)
          default: Request successful. This request will incur a charge.
        message_zh:
          type: string
          title: Message Zh
          description: Response message (ZH-CN) | 响应消息 (中文)
          default: 请求成功，本次请求将被计费。
        support:
          type: string
          title: Support
          description: Support message | 支持消息
          default: 'Discord: https://discord.gg/aMEAS8Xsvz'
        time:
          type: string
          title: Time
          description: The time the response was generated | 生成响应的时间
        time_stamp:
          type: integer
          title: Time Stamp
          description: The timestamp the response was generated | 生成响应的时间戳
        time_zone:
          type: string
          title: Time Zone
          description: The timezone of the response time | 响应时间的时区
          default: America/Los_Angeles
        docs:
          anyOf:
            - type: string
            - type: 'null'
          title: Docs
          description: >-
            Link to the API Swagger documentation for this endpoint | 此端点的 API
            Swagger 文档链接
        cache_message:
          anyOf:
            - type: string
            - type: 'null'
          title: Cache Message
          description: Cache message (EN-US) | 缓存消息 (English)
          default: >-
            This response is cached and accessible via the URL below for 24
            hours at no extra cost. The cache is for request tracing only — it
            doesn't affect the API's data freshness and won't be returned
            through the API again.
        cache_message_zh:
          anyOf:
            - type: string
            - type: 'null'
          title: Cache Message Zh
          description: Cache message (ZH-CN) | 缓存消息 (中文)
          default: >-
            本次响应已缓存，可通过下方 URL 直接查看，有效期 24
            小时，访问缓存链接无额外费用。缓存仅用于请求溯源，不影响接口数据的时效性，也不会再次通过接口返回。
        cache_url:
          anyOf:
            - type: string
            - type: 'null'
          title: Cache Url
          description: The URL to access the cached result | 访问缓存结果的 URL
        router:
          type: string
          title: Router
          description: The endpoint that generated this response | 生成此响应的端点
          default: ''
        params:
          type: string
        data:
          anyOf:
            - type: string
            - type: 'null'
          title: Data
          description: The response data | 响应数据
      type: object
      title: ResponseModel
      x-apifox-orders:
        - code
        - request_id
        - message
        - message_zh
        - support
        - time
        - time_stamp
        - time_zone
        - docs
        - cache_message
        - cache_message_zh
        - cache_url
        - router
        - params
        - data
      x-apifox-ignore-properties: []
      x-apifox-folder: ''
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
      x-apifox-orders:
        - detail
      x-apifox-ignore-properties: []
      x-apifox-folder: ''
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
      x-apifox-orders:
        - loc
        - msg
        - type
      x-apifox-ignore-properties: []
      x-apifox-folder: ''
  securitySchemes:
    HTTPBearer:
      type: bearer
      description: >
        ----

        #### API Token Introduction:

        ##### Method 1: Use API Token in the Request Header (Recommended)

        - **Header**: `Authorization`

        - **Format**: `Bearer {token}`

        - **Example**: `{"Authorization": "Bearer your_token"}`

        - **Swagger UI**: Click on the `Authorize` button in the upper right
        corner of the page to enter the API token directly without the `Bearer`
        keyword.


        ##### Method 2: Use API Token in the Cookie (Not Recommended, Use Only
        When Method 1 is Unavailable)

        - **Cookie**: `Authorization`

        - **Format**: `Bearer {token}`

        - **Example**: `Authorization=Bearer your_token`


        #### Get API Token:

        1. Register and log in to your account on the TikHub website.

        2. Go to the user center, click on the API token menu, and create an API
        token.

        3. Copy and use the API token in the request header.

        4. Keep your API token confidential and use it only in the request
        header.


        ----


        #### API令牌简介:

        ##### 方法一：在请求头中使用API令牌（推荐）

        - **请求头**: `Authorization`

        - **格式**: `Bearer {token}`

        - **示例**: `{"Authorization": "Bearer your_token"}`

        - **Swagger UI**: 点击页面右上角的`Authorize`按钮，直接输入API令牌，不需要`Bearer`关键字。


        ##### 方法二：在Cookie中使用API令牌（不推荐，仅在无法使用方法一时使用）

        - **Cookie**: `Authorization`

        - **格式**: `Bearer {token}`

        - **示例**: `Authorization=Bearer your_token`


        #### 获取API令牌:

        1. 在TikHub网站注册并登录账户。

        2. 进入用户中心，点击API令牌菜单，创建API令牌。

        3. 复制并在请求头中使用API令牌。

        4. 保密您的API令牌，仅在请求头中使用。
      scheme: bearer
servers:
  - url: https://api.tikhub.io
    description: Production Environment
security: []

```
