> ## 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 密钥。

调用方必须具有 ManageAccountServiceUsers 权限。

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

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


## OpenAPI

````yaml zh/v3-openapi.yaml POST /v3beta1/enterprise/service-users/{service_user_id}/api-keys
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:
    post:
      tags:
        - service_user_api_keys
      summary: 为服务用户创建 API 密钥
      description: |-
        为服务用户创建新的 API 密钥。

        调用方必须具有 ManageAccountServiceUsers 权限。
      operationId: >-
        handle_create_service_user_api_key_v3beta1_enterprise_service_users__service_user_id__api_keys_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
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateApiKeyRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyWithTokenResponse'
          description: 成功响应
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: 验证错误
components:
  schemas:
    CreateApiKeyRequest:
      properties:
        expires_at:
          anyOf:
            - type: integer
            - type: 'null'
          description: 可选的过期时间，以秒为单位的 UNIX 时间戳表示。如提供，则必须是未来时间。
          title: Expires At
        name:
          maxLength: 256
          minLength: 1
          title: Name
          type: string
      required:
        - name
      title: CreateApiKeyRequest
      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
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      type: object
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: Location
          type: array
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object
  securitySchemes:
    bearerAuth:
      description: 服务用户凭据（前缀：cog_）
      scheme: bearer
      type: http

````