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

# 修改成员角色

> 修改成员角色。将管理员降级为成员时，组织内至少需保留另一名管理员，否则返回 `400 last_admin_protected`。

> [!NOTE]
>
> 本接口要求 Admin Key 具备 `org:write` 作用域，且调用时 key 持有者仍是组织管理员（否则返回 `403 owner_not_admin`）。


## OpenAPI

````yaml PATCH /v1/admin/organizations/members/{uid}
openapi: 3.0.3
info:
  title: Kimi Admin API
  version: 2026-10-20-beta
  description: >-
    ## 概览


    Kimi Admin API 让组织管理员通过接口管理成员、邀请、项目与推理 API 密钥，并查询账单、用量与审计日志——无需登录控制台。它是管理面
    API：Admin API 凭证不能调用任何推理端点，推理 API key 也不能调用本 API。


    服务地址为 `https://api.moonshot.cn/v1`。


    <Note>

    Admin API 当前处于 **Beta** 阶段，面向已完成企业认证的组织开放。在「控制台 → 组织管理 →
    组织认证」完成企业认证后，组织管理员即可在「组织管理 → Admin API Keys」自助创建 Admin Key。

    </Note>


    ## 身份验证


    以 Bearer 方式发送 Admin API secret（`sk-admin-*`）：


    ```sh

    curl https://api.moonshot.cn/v1/admin/organizations \
      --header "Authorization: Bearer $MOONSHOT_ADMIN_KEY"
    ```


    每个 Admin API 密钥 固定绑定一个组织；组织永远从 key 推导——结构上不可能跨组织访问。key 的持有者退出组织或被注销后，key 在
    30 秒内失效。secret 仅在创建或轮换时展示一次，请妥善保存。


    ## 作用域（scope）


    每个 Admin API 密钥 在创建时选定权限域：


    | scope | 类型 | 覆盖范围 |

    | --- | --- | --- |

    | `billing:read` | 只读 | 日/产品账单、请求明细、中断请求、账户余额、用量聚合 |

    | `org:read` | 只读 | 成员、邀请、项目、项目成员、推理 API 密钥 元数据、项目支出限额、组织速率限制 |

    | `org:write` | 写 | 成员/邀请/项目/推理 API 密钥 写操作（隐含 `org:read`，无需单独授权） |

    | `audit:read` | 只读 | 审计日志事件 |

    | `all` | 读+写 | 以上全部；未来新增权限域自动覆盖 |


    写端点额外要求 key 持有者在调用时仍是组织管理员，且适用更严格的限流（见下）。


    ## 速率限制


    | 类别 | 限制 |

    | --- | --- |

    | 读端点 | 60 次/分钟/组织 |

    | 写端点 | 20 次/分钟/组织 |

    | 请求明细、中断请求、用量聚合 | 5 并发/组织 |


    限流按「组织 × 端点」计数：同一组织下的所有 Admin Key 共享限额，多把 key 不会获得更高配额。超限返回 `429
    rate_limit_exceeded` / `concurrency_limit_exceeded`。


    ## 分页


    分页端点（日/产品账单、请求明细、中断请求、用量聚合、审计日志）使用游标分页：响应携带 `has_more` 与 `next`；将 `next` 作为
    `cursor` 查询参数传回即可翻页。页大小按端点：日/产品账单与用量聚合默认 100、最大 1000；请求明细与中断请求默认 100、最大
    10000；审计日志默认 20、最大 100。游标只携带页位置——翻页时请原样重复全部过滤参数。


    组织集合端点（成员、邀请、项目、项目成员、推理 API 密钥）一次性全量返回，无分页参数。协议之外的查询参数（如
    `page_size`）会被静默忽略，请核对参数名。


    ## 错误格式


    错误响应遵循统一格式：


    ```json

    {
      "error": {
        "type": "invalid_request_error",
        "code": "invalid_date_range",
        "message": "end must be greater than start.",
        "param": "end",
        "request_id": "..."
      }
    }

    ```


    `data_not_ready` 专用于账单类端点的数据就绪规则：T 日数据于 T+1 日 07:00（UTC+8）起可查。


    ## 数据口径


    - 金额单位为毫分（1 元 = 100,000 毫分）。

    - 查询参数中的时间为 epoch 毫秒；响应体中的时间为 RFC 3339（另有说明除外）。

    - 时间窗左闭右开、按 CST 日界；查询参数中的时间为 epoch 毫秒，响应体中的时间为 RFC
    3339（另有说明除外）。按秒传入会返回空数据而非报错，请核对单位为毫秒。

    - 账单数据 T-1 就绪：当日数据次日早 7:00 CST 起可查，之前返回 `400
    data_not_ready`；中断请求明细不受此限（近实时可查）。

    - 数据留存与窗口：日/产品账单留存 365 天；请求明细与中断请求留存 90 天、单次窗口 ≤31 天；审计日志单次窗口 ≤31
    天；用量聚合窗口按粒度分档（`1m` ≤24 小时、`1h` ≤31 天、`1d` ≤93 天）。

    - 每个组织最多同时持有 10 把未删除 Admin Key。
servers:
  - url: https://api.moonshot.cn
    description: 生产环境
security:
  - AdminBearerAuth: []
paths:
  /v1/admin/organizations/members/{uid}:
    patch:
      tags:
        - 组织
      summary: 修改成员角色
      description: 修改成员角色。将管理员降级为成员时，组织内至少需保留另一名管理员，否则返回 `400 last_admin_protected`。
      operationId: updateOrgMemberRole
      parameters:
        - name: uid
          in: path
          required: true
          schema:
            type: string
          description: 成员的用户 ID。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OrgMemberRoleUpdateRequest'
      responses:
        '200':
          description: 更新后的成员。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrgMember'
        '400':
          description: 请求参数错误（字段非法/缺必填，或触发保护规则如最后一名管理员）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrgWriteErrorResponse'
        '401':
          description: 身份验证失败（Admin API key 无效、已删除/已过期，或 key 持有者已失效）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrgWriteErrorResponse'
        '403':
          description: 权限不足（缺少 org:write 作用域，或 key 持有者当前不是组织管理员）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrgWriteErrorResponse'
        '404':
          description: 成员不存在（uid 无效或不属于当前组织）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrgWriteErrorResponse'
        '429':
          description: 达到速率限制（每分钟请求数超限或并发超限）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrgWriteErrorResponse'
        '500':
          description: 服务内部错误（联系支持团队并提供 request_id）。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OrgWriteErrorResponse'
      security:
        - AdminBearerAuth: []
components:
  schemas:
    OrgMemberRoleUpdateRequest:
      type: object
      required:
        - role
      additionalProperties: false
      properties:
        role:
          type: string
          example: admin
          enum:
            - admin
            - member
          description: 目标角色：`admin` 或 `member`。
    OrgMember:
      type: object
      required:
        - uid
        - name
        - role
        - created_at
      additionalProperties: false
      properties:
        uid:
          type: string
          description: 成员的用户 ID。
        name:
          type: string
          description: 成员昵称。
        role:
          type: string
          enum:
            - admin
            - member
          description: 成员角色：`admin` 管理员、`member` 成员。
        created_at:
          type: string
          format: date-time
          description: 成员加入组织的时间（项目成员接口中则为加入项目的时间）。
    OrgWriteErrorResponse:
      type: object
      required:
        - error
      additionalProperties: false
      properties:
        error:
          $ref: '#/components/schemas/OrgWriteErrorBody'
    OrgWriteErrorBody:
      type: object
      required:
        - type
        - code
        - message
        - request_id
      additionalProperties: false
      properties:
        type:
          type: string
          example: invalid_request_error
        code:
          type: string
          description: 组织写域错误码（子集）。
          enum:
            - invalid_request
            - invalid_cursor
            - invalid_api_key
            - api_key_inactive
            - insufficient_scope
            - resource_not_found
            - member_not_found
            - project_not_found
            - key_not_found
            - invitation_not_found
            - last_admin_protected
            - owner_not_admin
            - rate_limit_exceeded
            - concurrency_limit_exceeded
            - internal_server_error
        message:
          type: string
        param:
          type: string
          nullable: true
        request_id:
          type: string
  securitySchemes:
    AdminBearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Admin API Secret (sk-admin-*)
      description: >-
        Authorization 请求头携带 Admin API secret 作为 Bearer 令牌，格式为 `Bearer
        sk-admin-***`。Admin Key 可在「控制台 → 组织管理 → Admin API Keys」创建。

````