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

# 创建账户服务账号

> 创建服务账号并仅显示一次其令牌。

<script src="/locale-bridge.js" />


## OpenAPI

````yaml /openapi.zh-cn.json POST /v1/public/accounts/{account_id}/auth/service-accounts
openapi: 3.1.0
info:
  title: Code API (Public)
  version: 1.0.0
servers:
  - url: https://api.hybridbox.io
security: []
paths:
  /v1/public/accounts/{account_id}/auth/service-accounts:
    post:
      tags:
        - public-accounts
        - public-account-auth
      summary: 创建账户服务账号
      description: 创建服务账号并仅显示一次其令牌。
      operationId: >-
        create_public_account_service_account_v1_public_accounts__account_id__auth_service_accounts_post
      parameters:
        - in: path
          name: account_id
          required: true
          schema:
            format: uuid
            title: Account Id
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ServiceAccountCreateRequest'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ServiceAccountCreateResponse'
          description: ''
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: 验证错误
      security:
        - PublicBearerAuth: []
components:
  schemas:
    ServiceAccountCreateRequest:
      description: 用于创建服务账号的请求正文。
      properties:
        expires_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          description: 可选的 UTC 令牌过期时间戳
          title: 过期时间
        name:
          description: 人类可读的服务账号名称
          maxLength: 120
          minLength: 1
          title: 名称
          type: string
      required:
        - name
      title: ServiceAccountCreateRequest
      type: object
    ServiceAccountCreateResponse:
      properties:
        account_id:
          format: uuid
          title: 账户 Id
          type: string
        created_at:
          format: date-time
          title: 创建时间
          type: string
        created_by_user_id:
          anyOf:
            - format: uuid
              type: string
            - type: 'null'
          title: 创建用户 ID
        expires_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: 过期时间
        id:
          format: uuid
          title: ID
          type: string
        last_used_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: 最后使用时间
        name:
          title: 名称
          type: string
        revoked_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: 撤销时间
        revoked_by_user_id:
          anyOf:
            - format: uuid
              type: string
            - type: 'null'
          title: 撤销者用户 ID
        token:
          description: 明文 bearer 令牌。请立即保存；它不会再次返回。
          title: 令牌
          type: string
        token_last4:
          title: 令牌后 4 位
          type: string
        token_prefix:
          title: 令牌前缀
          type: string
        token_public_id:
          title: 令牌公共 ID
          type: string
        updated_at:
          format: date-time
          title: 更新时间
          type: string
      required:
        - id
        - account_id
        - name
        - token_public_id
        - token_prefix
        - token_last4
        - created_at
        - updated_at
        - token
      title: ServiceAccountCreateResponse
      type: object
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: 详情
          type: array
      title: HTTPValidationError
      type: object
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: 位置
          type: array
        msg:
          title: 消息
          type: string
        type:
          title: 错误类型
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object
  securitySchemes:
    PublicBearerAuth:
      bearerFormat: JWT or Hybridbox Service account token
      description: >-
        Public API bearer credential sent as `Authorization: Bearer <token>`.
        Use either an OAuth access token or a Hybridbox Service account token.
      scheme: bearer
      type: http

````