> ## Documentation Index
> Fetch the complete documentation index at: https://docs.y.uno/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Test in the sandbox first: base URL https://api-sandbox.y.uno (Test Mode in the Dashboard). Production is https://api.y.uno (Live Mode).
> Every API request needs the public-api-key and private-secret-key headers. Get them in the Dashboard at https://dashboard.y.uno/developers (Developers > Credentials); sandbox and production keys are different.
> Send an X-Idempotency-Key (a UUID) when creating payments, refunds and cancels, so retries do not create duplicates.
> Start with the Quickstart (https://docs.y.uno/docs/quickstart.md) and the agent guide (https://docs.y.uno/agents.md). To search these docs from a coding agent, connect the docs MCP server at https://docs.y.uno/mcp.

# 创建计划

> 创建可重复使用的定价计划，可选按国家/地区定价和试用阶段阶梯。

> [!NOTE]
>
> **计划不可变更**
>
> 没有用于更新的 endpoint。更改价格意味着创建新的计划：现有订阅会保留在创建时所用的计划（和价格）上，直到您迁移它们或它们被取消。如需迁移，请使用[更改订阅计划](https://docs.y.uno/zh-hans/reference/subscriptions/change-subscription-plan.md)（立即替换），或使用[更新订阅](https://docs.y.uno/zh-hans/reference/subscriptions/update-subscription.md)上的 `plan_change` 对象（按计划执行，`id` 不变）。

有关可能的错误结果，请参阅 [HTTP 响应码](https://docs.y.uno/zh-hans/reference/getting-started/response-codes.md)部分。


## OpenAPI

````yaml openapi/zh-hans/plans/create-plan.json POST /subscriptions/plans
openapi: 3.1.0
info:
  title: plans
  version: 1.0.0
servers:
  - url: https://api-sandbox.y.uno/v1
    description: Sandbox
  - url: https://api.y.uno/v1
    description: Production (US)
security:
  - sec0: []
    sec1: []
paths:
  /subscriptions/plans:
    post:
      summary: 创建计划
      description: 创建可重复使用的定价计划。计划创建后不可变：如需调整价格，请创建新计划，旧计划下的现有订阅不受影响。
      operationId: create-plan
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - account_id
                - name
                - base_amount
                - frequency
              properties:
                name:
                  type: string
                  description: 计划名称（最多 255 个字符，最少 3 个字符）。
                description:
                  type: string
                  description: 计划描述。目前不限制长度。
                merchant_reference:
                  type: string
                  description: 您自己的计划标识符。目前不限制长度。
                base_amount:
                  type: object
                  description: 未在 `country_prices` 中明确列出的国家所使用的默认价格。
                  required:
                    - currency
                    - value
                  properties:
                    currency:
                      type: string
                      description: >-
                        MAX 3；MIN 3；[ISO
                        4217](/zh-hans/reference/country-reference)。
                    value:
                      type: number
                      description: 0.0001 的倍数。
                      format: float
                frequency:
                  type: object
                  description: 计划的计费频率。基于此计划创建的订阅会继承该频率。
                  required:
                    - type
                    - value
                  properties:
                    type:
                      type: string
                      enum:
                        - DAY
                        - WEEK
                        - MONTH
                        - QUARTER
                        - HALF_YEAR
                        - YEAR
                    value:
                      type: integer
                      format: int32
                country_prices:
                  type: array
                  description: 可选的按国家显式定价。未列出的国家使用 `base_amount`。
                  items:
                    type: object
                    properties:
                      country:
                        type: string
                        description: '[ISO 3166-1](/zh-hans/reference/country-reference)。'
                      amount:
                        type: object
                        properties:
                          currency:
                            type: string
                          value:
                            type: number
                            format: float
                allowed_payment_methods:
                  type: array
                  description: 此计划下的订阅所接受的支付方式类型。
                  items:
                    type: string
                metadata:
                  type: array
                  description: 附加到计划的键值对。与基于该计划创建的订阅上设置的任何 `metadata` 相互独立。
                  items:
                    type: object
                    properties:
                      key:
                        type: string
                        description: MAX 48。
                      value:
                        type: string
                        description: MAX 512。
                phases:
                  type: array
                  description: >-
                    可选的前置阶梯（例如试用期），位于计划的常规价格之前。固定价格的计划请省略。最后一项必须是没有 `duration`
                    的终止 REGULAR 阶段。
                  items:
                    type: object
                    required:
                      - order
                      - type
                      - name
                    properties:
                      order:
                        type: integer
                        format: int32
                      name:
                        type: string
                        description: 必填且不能为空，每个阶段都必须有名称。
                      type:
                        type: string
                        enum:
                          - TRIAL
                          - REGULAR
                      duration:
                        type: object
                        description: 每个非终止阶段必填，终止 REGULAR 阶段省略。
                        properties:
                          type:
                            type: string
                            enum:
                              - DAY
                              - WEEK
                              - MONTH
                              - YEAR
                          value:
                            type: integer
                            format: int32
                      frequency:
                        type: object
                        description: >-
                          可选。省略时，该阶段按一次性总额扣款，覆盖整个 `duration`。设置后，该阶段按每个
                          `frequency` 间隔扣款，服务器会计算 `total_payments = duration /
                          frequency`（两者使用相同单位），例如 3 个月的 duration 搭配 1 个月的
                          frequency 会产生 3 次扣款。不适用于终止阶段。
                        properties:
                          type:
                            type: string
                            enum:
                              - DAY
                              - WEEK
                              - MONTH
                              - QUARTER
                              - HALF_YEAR
                              - YEAR
                          value:
                            type: integer
                            format: int32
                      amount:
                        type: object
                        description: >-
                          该阶段的固定价格。允许为 0（免费试用）。在**非终止**阶段，此字段与 `country_prices`
                          二选一，必须提供其一。在**终止** REGULAR 阶段，请完全省略此字段，发送该字段会被拒绝并返回
                          `400 BAD_REQUEST`（“The terminal phase price comes from
                          the plan base_amount/country_prices - remove the phase
                          amount”），终止阶段的价格始终来自计划自身的
                          `base_amount`/`country_prices`。
                        properties:
                          currency:
                            type: string
                          value:
                            type: number
                            format: float
                      country_prices:
                        type: array
                        description: >-
                          该阶段按国家的定价。在非终止阶段，此字段与 `amount`
                          二选一，必须提供其一。不适用于终止阶段，其定价始终来自计划自身的 `country_prices`。
                        items:
                          type: object
                          properties:
                            country:
                              type: string
                            amount:
                              type: object
                              properties:
                                currency:
                                  type: string
                                value:
                                  type: number
                                  format: float
                account_id:
                  type: string
                  description: >-
                    在 [Yuno Dashboard](https://dashboard.y.uno/developers) 中找到的
                    `account_id`（UUID）。必填。在此 endpoint 上，账户通过请求体发送，而不是通过
                    `X-Account-Code` 标头。
            examples:
              Plan:
                value:
                  account_id: <your account_id>
                  name: Streaming Pro
                  description: Access to Pro features, billed monthly
                  merchant_reference: streaming-pro-monthly
                  base_amount:
                    currency: USD
                    value: 20
                  frequency:
                    type: MONTH
                    value: 1
                  country_prices:
                    - country: US
                      amount:
                        currency: USD
                        value: 20
                    - country: BR
                      amount:
                        currency: BRL
                        value: 99.9
                  allowed_payment_methods:
                    - CARD
                    - PIX
                  metadata:
                    - key: campaign
                      value: app_store
                  phases:
                    - order: 1
                      name: Intro
                      type: TRIAL
                      duration:
                        type: MONTH
                        value: 3
                      frequency:
                        type: MONTH
                        value: 1
                      amount:
                        currency: USD
                        value: 9.99
                      country_prices:
                        - country: BR
                          amount:
                            currency: BRL
                            value: 49.9
                    - order: 2
                      name: Regular
                      type: REGULAR
      responses:
        '201':
          description: '201'
          content:
            application/json:
              examples:
                Result:
                  value:
                    id: 00000000-0000-4000-8000-000000000001
                    account_id: 00000000-0000-4000-8000-000000000002
                    name: Streaming Pro
                    description: Access to Pro features, billed monthly
                    merchant_reference: streaming-pro-monthly
                    status: ACTIVE
                    base_amount:
                      currency: USD
                      value: 20
                    frequency:
                      type: MONTH
                      value: 1
                    country_prices:
                      - country: US
                        amount:
                          currency: USD
                          value: 20
                      - country: BR
                        amount:
                          currency: BRL
                          value: 99.9
                    allowed_payment_methods:
                      - CARD
                      - PIX
                    metadata:
                      - key: campaign
                        value: app_store
                    phases:
                      - order: 1
                        name: Intro
                        type: TRIAL
                        duration:
                          type: MONTH
                          value: 3
                        frequency:
                          type: MONTH
                          value: 1
                        amount:
                          currency: USD
                          value: 9.99
                      - order: 2
                        name: Regular
                        type: REGULAR
                    created_at: '2024-01-15T10:30:00.000000Z'
                    updated_at: '2024-01-15T10:30:00.000000Z'
                    account_ids:
                      - a5b50509-2f47-444e-8056-feb736ad89ae
                    retries: null
                    retry_split: null
                    meters: []
              schema:
                type: object
                properties:
                  id:
                    type: string
                  account_id:
                    type: string
                  name:
                    type: string
                  description:
                    type: string
                    nullable: true
                  merchant_reference:
                    type: string
                  status:
                    type: string
                    example: ACTIVE
                  base_amount:
                    type: object
                    properties:
                      currency:
                        type: string
                      value:
                        type: number
                  frequency:
                    type: object
                    properties:
                      type:
                        type: string
                      value:
                        type: integer
                  country_prices:
                    type: array
                    items:
                      type: object
                      properties:
                        country:
                          type: string
                        amount:
                          type: object
                          properties:
                            currency:
                              type: string
                            value:
                              type: number
                  allowed_payment_methods:
                    type: array
                    items:
                      type: string
                  metadata:
                    type: array
                    items:
                      type: object
                  phases:
                    type: array
                    items:
                      type: object
                  created_at:
                    type: string
                  updated_at:
                    type: string
                  account_ids:
                    type: array
                    items:
                      type: string
                    description: 账户 ID。
                  retries:
                    nullable: true
                    description: 重试。
                  retry_split:
                    nullable: true
                    description: 重试拆分。
                  meters:
                    type: array
                    items: {}
                    description: 计量器。
        '400':
          description: '400'
          content:
            application/json:
              examples:
                Result:
                  value:
                    code: INVALID_REQUEST
                    messages:
                      - Invalid request
                  summary: Result
      deprecated: false
components:
  securitySchemes:
    sec0:
      type: apiKey
      in: header
      name: public-api-key
      x-default: <Your public-api-key>
    sec1:
      type: apiKey
      in: header
      name: private-secret-key
      x-default: <Your private-secret-key>

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.