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

# Create a workspace

> Create a new workspace with the given name, on the chosen branch or commit. If neither is specified, the default branch is used. If a commit is specified, the workspace will be created on that commit, in a "detached" state, meaning it will not be associated with any branch and new commits cannot be published by it.



## OpenAPI

````yaml post /repos/{repo_id}/workspaces
openapi: 3.0.3
info:
  title: Diversion Core API
  description: >-
    Definition of the Core API used to access low-level functionality of
    Diversion
  version: 0.2.0
servers:
  - url: https://api.diversion.dev/v0
    description: Base endpoint
security: []
paths:
  /repos/{repo_id}/workspaces:
    parameters:
      - $ref: '#/components/parameters/RepoParam'
    post:
      tags:
        - Repository Workspace Manipulation
      summary: Create a workspace
      description: Create a new workspace
      operationId: src.handlersv2.workspace.create_workspace
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewWorkspace'
      responses:
        '201':
          $ref: '#/components/responses/Created'
        '409':
          $ref: '#/components/responses/Error'
          description: Workspace with the same name already exists
        default:
          $ref: '#/components/responses/Error'
      security:
        - OAuth2:
            - coreapi/write
components:
  parameters:
    RepoParam:
      in: path
      name: repo_id
      required: true
      schema:
        type: string
        example: example_id
        minLength: 3
        maxLength: 128
      description: >-
        The repo ID of the repository. Repo _name_ can be used instead of the
        ID, but usage of ID for permanent linking and API requests is preferred.
  schemas:
    NewWorkspace:
      type: object
      properties:
        branch_id:
          type: string
        name:
          type: string
        commit_id:
          type: string
          example: example_id
          minLength: 3
          maxLength: 128
    NewResourceId:
      type: object
      properties:
        id:
          type: string
          description: The id of the newly created resource
          example: example_id
      required:
        - id
    Error:
      type: object
      properties:
        status:
          type: integer
          description: HTTP status code
          example: 403
        detail:
          type: string
          example: User not authorized to perform the requested action on the resource
        title:
          type: string
        type:
          type: string
      required:
        - status
        - detail
  responses:
    Created:
      description: Resource created
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NewResourceId'
    Error:
      description: An error occurred
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    OAuth2:
      type: oauth2
      x-tokenInfoFunc: src.token_info.token_auth
      description: This API uses OAuth 2 with the implicit grant flow
      flows:
        implicit:
          authorizationUrl: https://auth.diversion.dev/oauth2/authorize
          scopes:
            coreapi/read: Operations with no possible side-effects
            coreapi/write: Modifying operations
            coreapi/admin: >-
              Organizational operations like adding a repo or changing repo
              properties

````