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

# Create Folder

Creates a new folder in the workspace. Folders can be nested within other folders by providing a parent\_id. The folder name must be unique within its parent folder (or at the root level if no parent is specified).


## OpenAPI

````yaml POST /api/public/v2/folders
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers: []
security:
  - ApiKeyAuth: []
paths:
  /api/public/v2/folders:
    post:
      tags:
        - folders
      summary: Create Folder
      operationId: create_folder_api_public_v2_folders_post
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateFolderRequest'
      responses:
        '201':
          description: Folder created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateFolderSuccessResponse'
        '400':
          description: Bad request - Invalid input or folder name already exists
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/FolderExistsError'
                  - type: string
                    example: Invalid workspace_id
        '401':
          description: Unauthorized - Missing or invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorizedError'
        '404':
          description: Parent folder not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ParentFolderNotFoundError'
        '409':
          description: External ID conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExternalIdErrorResponse'
        '422':
          $ref: '#/components/responses/ValidationError'
components:
  schemas:
    CreateFolderRequest:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 255
          description: The name of the folder. Must be unique within its parent folder.
        parent_id:
          type: integer
          nullable: true
          description: >-
            The ID of the parent folder. If null or not provided, the folder
            will be created at the root level of the workspace.
        workspace_id:
          type: integer
          minimum: 1
          description: >-
            Optional workspace ID. If not provided, uses the workspace
            associated with your API key.
        external_ids:
          type: array
          items:
            $ref: '#/components/schemas/ExternalId'
          description: Identifiers from other systems.
      title: CreateFolderRequest
    CreateFolderSuccessResponse:
      type: object
      properties:
        success:
          type: boolean
          description: Indicates if the operation was successful
        folder:
          $ref: '#/components/schemas/Folder'
      title: CreateFolderSuccessResponse
    FolderExistsError:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
      title: FolderExistsError
    UnauthorizedError:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
      title: UnauthorizedError
    ParentFolderNotFoundError:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
      title: ParentFolderNotFoundError
    ExternalIdErrorResponse:
      properties:
        success:
          type: boolean
          const: false
          default: false
          title: Success
        message:
          type: string
          title: Message
      type: object
      required:
        - message
      title: ExternalIdErrorResponse
    ExternalId:
      properties:
        source:
          type: string
          maxLength: 128
          minLength: 1
          title: Source
          description: The external system or namespace that owns the ID.
        external_id:
          type: string
          maxLength: 512
          minLength: 1
          title: External Id
          description: The identifier for this entity in the external system.
      type: object
      required:
        - source
        - external_id
      additionalProperties: false
      title: ExternalId
      description: >-
        Customer-defined mapping between a PromptLayer entity and an external
        system identifier.
    Folder:
      type: object
      properties:
        id:
          type: integer
          description: Unique identifier for the folder
        name:
          type: string
          description: The name of the folder
        created_at:
          type: string
          format: date-time
          description: Timestamp when the folder was created
        updated_at:
          type: string
          format: date-time
          description: Timestamp when the folder was last updated
        path:
          type: array
          nullable: true
          items:
            type: object
          description: >-
            JSON array representing the folder hierarchy path. Contains the IDs
            and names of all parent folders. Null for root-level folders.
        workspace_id:
          type: integer
          description: ID of the workspace this folder belongs to
        parent_id:
          type: integer
          nullable: true
          description: ID of the parent folder. Null for root-level folders.
        external_ids:
          type: array
          items:
            $ref: '#/components/schemas/ExternalId'
          description: External ID mappings for the folder.
      title: Folder
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          default: false
          description: Indicates that the request failed.
        message:
          type: string
          description: Human-readable error message.
        error:
          type: string
          description: Machine-readable or fallback error message.
      additionalProperties: true
      description: >-
        Standard error response. Some legacy endpoints may return either message
        or error.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  responses:
    ValidationError:
      description: Validation error - request parameters or body are invalid.
      content:
        application/json:
          schema:
            oneOf:
              - $ref: '#/components/schemas/HTTPValidationError'
              - $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-KEY

````