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

# 轮换服务用户的 API 密钥

> 轮换服务用户的 API 密钥。

创建一个新密钥。默认会撤销旧密钥；将 revoke_current=false
设为 false 可实现平滑轮换，使两个密钥暂时同时保持有效。
如果未找到该密钥，则返回 404；如果该密钥未处于有效状态，则返回 400。

<div id="permissions">
  ## 权限
</div>

需要具备企业级 `ManageAccountServiceUsers` 权限的服务用户。


## OpenAPI

````yaml zh/v3-openapi.yaml POST /v3beta1/enterprise/service-users/{service_user_id}/api-keys/{api_key_id}/rotate
openapi: 3.1.0
info:
  description: 采用 Service User 身份验证和 RBAC 的 Devin v3 API
  title: Devin API v3
  version: 3.0.0
servers: []
security:
  - bearerAuth: []
paths:
  /v3beta1/enterprise/service-users/{service_user_id}/api-keys/{api_key_id}/rotate:
    post:
      tags:
        - service_user_api_keys
      summary: 轮换服务用户的 API 密钥
      description: |-
        轮换服务用户的 API 密钥。

        创建一个新密钥。默认会撤销旧密钥；将 revoke_current=false
        设为 false 可实现平滑轮换，使两个密钥暂时同时保持有效。
        如果未找到该密钥，则返回 404；如果该密钥未处于有效状态，则返回 400。
      operationId: >-
        handle_rotate_service_user_api_key_v3beta1_enterprise_service_users__service_user_id__api_keys__api_key_id__rotate_post
      parameters:
        - description: 服务用户 ID（前缀：service-user-）
          in: path
          name: service_user_id
          required: true
          schema:
            example: service-user-abc123def456
            title: Service User Id
            type: string
        - in: path
          name: api_key_id
          required: true
          schema:
            title: Api Key Id
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RotateApiKeyRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyWithTokenResponse'
          description: 成功响应
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 未经授权
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 禁止访问
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 未找到
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 冲突
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 无法处理的内容
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: 请求过多
components:
  schemas:
    RotateApiKeyRequest:
      properties:
        new_key_expires_at:
          anyOf:
            - type: integer
            - type: 'null'
          description: 新密钥的可选过期时间，以秒为单位的 UNIX 时间戳。Null 表示不过期。
          title: New Key Expires At
        revoke_current:
          default: true
          description: 是否撤销当前密钥。设为 False 可进行平滑轮换。
          title: Revoke Current
          type: boolean
      title: RotateApiKeyRequest
      type: object
    ApiKeyWithTokenResponse:
      description: API 密钥创建/轮换的共享响应模型（包含一次性令牌）。
      properties:
        api_key_id:
          title: Api Key Id
          type: string
        api_key_name:
          title: Api Key Name
          type: string
        token:
          description: 原始 API 令牌。该令牌仅会在创建或轮换时显示一次。
          title: Token
          type: string
      required:
        - api_key_id
        - api_key_name
        - token
      title: ApiKeyWithTokenResponse
      type: object
    ProblemDetail:
      description: >-
        v3 API 的 RFC 9457 application/problem+json 错误响应体。


        detail 沿用自旧版 {"detail": ...} 响应体，以保持向后兼容；其他成员字段为新增字段。errors
        包含字段级验证失败信息（仅 422）。
      properties:
        detail:
          anyOf:
            - type: string
            - type: 'null'
          description: 针对此次具体情况的、便于人理解的说明。
          title: Detail
        errors:
          anyOf:
            - items:
                additionalProperties: true
                type: object
              type: array
            - type: 'null'
          description: 字段级验证错误（仅适用于 422 响应）。
          title: Errors
        instance:
          anyOf:
            - type: string
            - type: 'null'
          description: 此次出现对应的 URI 引用（请求路径）。
          title: Instance
        status:
          description: HTTP 状态码。
          title: Status
          type: integer
        title:
          description: 对问题类型的简短、便于理解的概述。
          title: Title
          type: string
        type:
          default: about:blank
          description: 用于标识问题类型的 URI 引用。
          title: Type
          type: string
      required:
        - title
        - status
      title: ProblemDetail
      type: object
  securitySchemes:
    bearerAuth:
      description: 服务用户凭据（前缀：cog_）
      scheme: bearer
      type: http

````