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

# Create a service account

> Create a new service account in the organization. API keys are minted
separately via the `/{name}/api-keys` endpoint.



## OpenAPI

````yaml https://app.kosli.com/api/v2/openapi.json post /service-accounts/{org}
openapi: 3.1.0
info:
  title: Kosli API
  summary: The API for communicating with Kosli
  description: >

    # Authentication 


    When making requests against Kosli API, you can authenticate your requests
    using a bearer token. 

    Set the bearer token in the request Authorization header to a valid API
    key. 

    API Keys can be personal or for service accounts. Check the [service
    accounts
    documentation](https://docs.kosli.com/getting_started/service-accounts/) for
    details. 


    ## Curl example


    ```shell

    curl -H "Authorization: Bearer <<your-api-key>>"
    https://app.kosli.com/api/v2/environments/<<your-org-name>>

    ```
  version: '2.0'
servers:
  - url: https://app.kosli.com/api/v2
    description: EU
  - url: https://app.us.kosli.com/api/v2
    description: US
security:
  - HTTPBearer: []
paths:
  /service-accounts/{org}:
    post:
      tags:
        - Service Accounts
      summary: Create a service account
      description: |-
        Create a new service account in the organization. API keys are minted
        separately via the `/{name}/api-keys` endpoint.
      operationId: create_service_account
      parameters:
        - name: org
          in: path
          required: true
          schema:
            type: string
            title: Org
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ServiceAccountPostInput'
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ServiceAccountResponse'
        '400':
          description: Invalid name or privilege
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/fastapi_app__errors__ValidationErrorResponse___locals___ValidationErrorResponseModel__16
        '403':
          description: Forbidden (e.g. personal org, or insufficient role)
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/fastapi_app__errors__ForbiddenResponse___locals___ForbiddenResponseModel__19
        '409':
          description: Service account name already exists
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/fastapi_app__errors__ConflictResponse___locals___ConflictResponseModel__2
      security:
        - HTTPBearer: []
        - HTTPBasic: []
components:
  schemas:
    ServiceAccountPostInput:
      properties:
        name:
          type: string
          maxLength: 64
          minLength: 1
          pattern: ^[a-zA-Z0-9\-]+$
          title: Name
        description:
          anyOf:
            - type: string
              maxLength: 512
            - type: 'null'
          title: Description
        privilege:
          type: string
          enum:
            - admin
            - member
            - snapshotter
            - reader
          title: Privilege
          default: reader
      type: object
      required:
        - name
      title: ServiceAccountPostInput
    ServiceAccountResponse:
      properties:
        name:
          type: string
          title: Name
        display_name:
          type: string
          title: Display Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
        privilege:
          type: string
          enum:
            - admin
            - member
            - snapshotter
            - reader
          title: Privilege
        creating_user_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Creating User Id
        created_at:
          anyOf:
            - type: number
            - type: 'null'
          title: Created At
        for_webhook:
          anyOf:
            - type: boolean
            - type: 'null'
          title: For Webhook
      type: object
      required:
        - name
        - display_name
        - privilege
      title: ServiceAccountResponse
    fastapi_app__errors__ValidationErrorResponse___locals___ValidationErrorResponseModel__16:
      properties:
        message:
          type: string
          title: Message
          description: Error message
        errors:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Errors
          description: Validation errors by field
      type: object
      required:
        - message
      title: ValidationErrorResponseModel
      examples:
        - errors:
            email: Field must be a valid email address
            name: Field cannot be empty
          message: Input payload validation failed
    fastapi_app__errors__ForbiddenResponse___locals___ForbiddenResponseModel__19:
      properties:
        message:
          type: string
          title: Message
          description: Error message
        errors:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Errors
          description: Validation errors by field
      type: object
      required:
        - message
      title: ForbiddenResponseModel
      examples:
        - message: You don't have permission to access this resource
    fastapi_app__errors__ConflictResponse___locals___ConflictResponseModel__2:
      properties:
        message:
          type: string
          title: Message
          description: Error message
        errors:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Errors
          description: Validation errors by field
      type: object
      required:
        - message
      title: ConflictResponseModel
      description: Service account already exists
      examples:
        - message: Service account already exists
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````