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

# Post v1workspaces service accounts



## OpenAPI

````yaml /api-reference/openapi.json post /v1/workspaces/{workspaceId}/service-accounts
openapi: 3.1.0
info:
  title: sndbox Control Plane API
  version: 0.5.0
  description: >-
    Versioned v1 route and transport contract. Resource schemas remain additive
    during the v0.5 GA candidate.
servers:
  - url: https://api.sndbox.app
security: []
paths:
  /v1/workspaces/{workspaceId}/service-accounts:
    post:
      tags:
        - workspaces
      operationId: post_v1_workspaces_workspaceId_service_accounts
      parameters:
        - name: workspaceId
          in: path
          required: true
          schema:
            type: string
        - $ref: '#/components/parameters/CorrelationId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ServiceAccountInput'
      responses:
        '200':
          description: Successful response.
          headers:
            x-correlation-id:
              $ref: '#/components/headers/CorrelationId'
            idempotency-replayed:
              $ref: '#/components/headers/IdempotencyReplayed'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ServiceAccountEnvelope'
        '400':
          $ref: '#/components/responses/ApiError'
        '401':
          $ref: '#/components/responses/ApiError'
        '403':
          $ref: '#/components/responses/ApiError'
        '404':
          $ref: '#/components/responses/ApiError'
        '409':
          $ref: '#/components/responses/ApiError'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/ApiError'
        '503':
          $ref: '#/components/responses/ApiError'
      security:
        - bearerAuth: []
components:
  parameters:
    CorrelationId:
      name: x-correlation-id
      in: header
      required: false
      schema:
        type: string
        minLength: 8
        maxLength: 128
        pattern: ^[A-Za-z0-9][A-Za-z0-9._:-]+$
      description: Caller-supplied correlation ID; the server generates one when omitted.
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      schema:
        type: string
        minLength: 16
        maxLength: 200
        pattern: ^[A-Za-z0-9._:-]+$
      description: Enables exact replay for mutating requests for 24 hours.
  schemas:
    ServiceAccountInput:
      type: object
      required:
        - name
        - roleId
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 120
        description:
          type: string
          maxLength: 1000
          default: ''
        roleId:
          type: string
          format: uuid
        environmentIds:
          type: array
          items:
            type: string
            format: uuid
          default: []
        expiryPolicyDays:
          type: integer
          minimum: 1
          maximum: 365
          default: 90
      additionalProperties: false
    ServiceAccountEnvelope:
      type: object
      required:
        - serviceAccount
      properties:
        serviceAccount:
          $ref: '#/components/schemas/ServiceAccount'
      additionalProperties: false
    ServiceAccount:
      type: object
      required:
        - id
        - organisationId
        - workspaceId
        - name
        - description
        - ownerAccountIds
        - roleId
        - environmentIds
        - expiryPolicyDays
        - status
        - createdAt
        - lastUsedAt
      properties:
        id:
          type: string
          format: uuid
        organisationId:
          type: string
          format: uuid
        workspaceId:
          oneOf:
            - type: string
              format: uuid
            - type: 'null'
        name:
          type: string
        description:
          type: string
        ownerAccountIds:
          type: array
          items:
            type: string
            format: uuid
        roleId:
          type: string
          format: uuid
        environmentIds:
          type: array
          items:
            type: string
            format: uuid
        expiryPolicyDays:
          type: integer
        status:
          type: string
          enum:
            - active
            - suspended
            - revoked
        createdAt:
          type: string
          format: date-time
        lastUsedAt:
          oneOf:
            - type: string
              format: date-time
            - type: 'null'
      additionalProperties: false
    ApiError:
      type: object
      required:
        - error
        - correlationId
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
            details: {}
        correlationId:
          type: string
  headers:
    CorrelationId:
      schema:
        type: string
      description: Correlation ID for this request.
    IdempotencyReplayed:
      schema:
        type: string
        enum:
          - 'true'
      description: Present only when the response was replayed.
  responses:
    ApiError:
      description: Structured API error.
      headers:
        x-correlation-id:
          schema:
            type: string
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    RateLimited:
      description: Rate limit exceeded.
      headers:
        retry-after:
          schema:
            type: integer
        x-ratelimit-limit:
          schema:
            type: integer
        x-ratelimit-remaining:
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````