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

# Create a coding environment with existing preparation behavior

> Creates an environment with its packages, encrypted variables and 1 to 50 repositories, and starts environment preparation. Repositories start in the preparing status. The name is limited to 48 characters.

> [tab] CLI Tool
>
> ```bash
> coderabbit api request /code/environments --input request.json
> ```
>
> To install and sign in to the CLI, see [Call from the CLI](https://docs.coderabbit.ai/api/cli.md).

> [tab] MCP Server
>
> An agent connected to the [CodeRabbit MCP server](https://docs.coderabbit.ai/api/mcp.md) runs this operation as the `create_code_environment` tool. The connection selects the organization, so the arguments have no `org_id` or `org_name`.
>
> ```json
> {
>   "method": "tools/call",
>   "params": {
>     "name": "create_code_environment",
>     "arguments": {
>       "name": "<name>",
>       "repositories": []
>     }
>   }
> }
> ```


## OpenAPI

````yaml /openapi.json post /v1/code/environments
openapi: 3.0.0
info:
  title: CodeRabbit API
  version: 1.0.0
  description: >-
    Read and manage CodeRabbit reviews, coding tasks, Verify, Triage, security
    findings, Knowledge Base, configuration, and users for your organization.
servers:
  - url: https://api.coderabbit.ai
    description: US region
  - url: https://api.eu.coderabbit.ai
    description: EU region
security:
  - ApiKeyAuth: []
tags:
  - name: Organizations and repositories
  - name: Pull requests and reviews
  - name: Coding Agent
  - name: Coding environments
  - name: Verify
  - name: Triage
  - name: Security
  - name: Knowledge Base
  - name: Automations
  - name: Reports
  - name: Configuration
  - name: Connections
  - name: Users and roles
  - name: Usage and metrics
paths:
  /v1/code/environments:
    post:
      tags:
        - Coding environments
      summary: Create a coding environment with existing preparation behavior
      description: >-
        Creates an environment with its packages, encrypted variables and 1 to
        50 repositories, and starts environment preparation. Repositories start
        in the preparing status. The name is limited to 48 characters.
      operationId: create_code_environment
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 48
                description:
                  anyOf:
                    - type: string
                      maxLength: 512
                    - type: string
                      nullable: true
                      enum:
                        - null
                packages:
                  type: array
                  maxItems: 12
                  items:
                    type: object
                    properties:
                      id:
                        enum:
                          - python
                          - nodejs
                          - ruby
                          - rust
                          - go
                          - bun
                          - java
                        type: string
                      version:
                        type: string
                        minLength: 1
                        maxLength: 64
                    required:
                      - id
                      - version
                  default: []
                variables:
                  type: array
                  maxItems: 100
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                        maxLength: 255
                        pattern: ^[A-Za-z_][A-Za-z0-9_]*$
                      value:
                        type: string
                        maxLength: 4000
                      isSecret:
                        type: boolean
                    required:
                      - name
                      - value
                      - isSecret
                  default: []
                repositories:
                  type: array
                  minItems: 1
                  maxItems: 50
                  items:
                    type: object
                    properties:
                      repository:
                        type: object
                        properties:
                          provider:
                            enum:
                              - github
                              - gitlab
                              - azure-devops
                              - bitbucket
                              - gerrit
                            type: string
                          repositoryId:
                            type: string
                            minLength: 1
                            maxLength: 255
                          repositoryName:
                            type: string
                            minLength: 1
                            maxLength: 512
                        required:
                          - provider
                          - repositoryId
                          - repositoryName
                      setup:
                        type: object
                        properties:
                          machineSize:
                            enum:
                              - S
                              - M
                              - L
                            type: string
                          setupMethod:
                            enum:
                              - automatic
                              - custom
                            type: string
                            default: automatic
                          setupScript:
                            anyOf:
                              - type: string
                                maxLength: 50000
                              - type: string
                                nullable: true
                                enum:
                                  - null
                          startupScript:
                            anyOf:
                              - type: string
                                maxLength: 50000
                              - type: string
                                nullable: true
                                enum:
                                  - null
                          startupInstructions:
                            anyOf:
                              - type: string
                                maxLength: 10000
                              - type: string
                                nullable: true
                                enum:
                                  - null
                    required:
                      - repository
                      - setup
                org_id:
                  type: string
                  minLength: 1
                  description: >-
                    Organization for a workspace key: the Git-provider
                    organization ID (scope.provider_organization_id) or the
                    CodeRabbit organization ID (scope.id, or id from list
                    organizations). Supply either org_id or org_name, never
                    both. Omit for organization keys and MCP connections.
                org_name:
                  type: string
                  pattern: ^[A-Za-z0-9][A-Za-z0-9-]{0,38}$
                  description: >-
                    GitHub organization login, such as coderabbitai, not its
                    display name. Matched case-insensitively within the
                    authenticated workspace. Supply either org_name or org_id,
                    never both; omit for organization keys and MCP connections.
              required:
                - name
                - repositories
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  environment:
                    type: object
                    properties:
                      id:
                        type: string
                      name:
                        type: string
                      description:
                        anyOf:
                          - type: string
                          - type: string
                            nullable: true
                            enum:
                              - null
                      status:
                        enum:
                          - preparing
                          - ready
                          - failed
                          - archived
                        type: string
                      packages:
                        type: array
                        maxItems: 12
                        items:
                          type: object
                          properties:
                            id:
                              enum:
                                - python
                                - nodejs
                                - ruby
                                - rust
                                - go
                                - bun
                                - java
                              type: string
                            version:
                              type: string
                              minLength: 1
                              maxLength: 64
                          required:
                            - id
                            - version
                      revision:
                        type: number
                      configurationVersion:
                        type: string
                      preparedRevision:
                        anyOf:
                          - type: number
                          - type: string
                            nullable: true
                            enum:
                              - null
                      activeSnapshotRecordId:
                        anyOf:
                          - type: string
                          - type: string
                            nullable: true
                            enum:
                              - null
                      repositoryCount:
                        type: number
                      createdAt:
                        type: string
                      updatedAt:
                        type: string
                      archivedAt:
                        anyOf:
                          - type: string
                          - type: string
                            nullable: true
                            enum:
                              - null
                    required:
                      - id
                      - name
                      - description
                      - status
                      - packages
                      - revision
                      - configurationVersion
                      - preparedRevision
                      - activeSnapshotRecordId
                      - repositoryCount
                      - createdAt
                      - updatedAt
                      - archivedAt
                  repositories:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        environmentId:
                          type: string
                        repositoryProvider:
                          type: string
                        repositoryId:
                          type: string
                        repositoryName:
                          type: string
                        status:
                          enum:
                            - preparing
                            - active
                            - failed
                            - replaced
                            - removed
                          type: string
                        machineSize:
                          type: string
                        setupMethod:
                          type: string
                        setupScript:
                          anyOf:
                            - type: string
                            - type: string
                              nullable: true
                              enum:
                                - null
                        startupScript:
                          anyOf:
                            - type: string
                            - type: string
                              nullable: true
                              enum:
                                - null
                        startupInstructions:
                          anyOf:
                            - type: string
                            - type: string
                              nullable: true
                              enum:
                                - null
                        configRevision:
                          type: number
                        preparedRevision:
                          anyOf:
                            - type: number
                            - type: string
                              nullable: true
                              enum:
                                - null
                        setupAgentTaskId:
                          anyOf:
                            - type: string
                            - type: string
                              nullable: true
                              enum:
                                - null
                        lastPreparedAt:
                          anyOf:
                            - type: string
                            - type: string
                              nullable: true
                              enum:
                                - null
                        lastError:
                          anyOf:
                            - type: string
                            - type: string
                              nullable: true
                              enum:
                                - null
                        createdAt:
                          type: string
                        updatedAt:
                          type: string
                      required:
                        - id
                        - environmentId
                        - repositoryProvider
                        - repositoryId
                        - repositoryName
                        - status
                        - machineSize
                        - setupMethod
                        - setupScript
                        - startupScript
                        - startupInstructions
                        - configRevision
                        - preparedRevision
                        - setupAgentTaskId
                        - lastPreparedAt
                        - lastError
                        - createdAt
                        - updatedAt
                required:
                  - environment
                  - repositories
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        enum:
                          - invalid_request
                        type: string
                      message:
                        type: string
                      retry_after:
                        type: integer
                        minimum: 0
                        exclusiveMinimum: true
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        enum:
                          - unauthenticated
                        type: string
                      message:
                        type: string
                      retry_after:
                        type: integer
                        minimum: 0
                        exclusiveMinimum: true
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        enum:
                          - forbidden
                        type: string
                      message:
                        type: string
                      retry_after:
                        type: integer
                        minimum: 0
                        exclusiveMinimum: true
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        enum:
                          - not_found
                        type: string
                      message:
                        type: string
                      retry_after:
                        type: integer
                        minimum: 0
                        exclusiveMinimum: true
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        enum:
                          - head_changed
                          - conflict
                        type: string
                      message:
                        type: string
                      retry_after:
                        type: integer
                        minimum: 0
                        exclusiveMinimum: true
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '412':
          description: Precondition failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        enum:
                          - precondition_failed
                        type: string
                      message:
                        type: string
                      retry_after:
                        type: integer
                        minimum: 0
                        exclusiveMinimum: true
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '413':
          description: Content too large
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        enum:
                          - payload_too_large
                        type: string
                      message:
                        type: string
                      retry_after:
                        type: integer
                        minimum: 0
                        exclusiveMinimum: true
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '429':
          description: Too many requests
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        enum:
                          - rate_limit_exceeded
                        type: string
                      message:
                        type: string
                      retry_after:
                        type: integer
                        minimum: 0
                        exclusiveMinimum: true
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        enum:
                          - internal_error
                        type: string
                      message:
                        type: string
                      retry_after:
                        type: integer
                        minimum: 0
                        exclusiveMinimum: true
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
        '503':
          description: Service unavailable
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - unavailable
                      message:
                        type: string
                      retry_after:
                        type: integer
                        minimum: 0
                        exclusiveMinimum: true
                    required:
                      - code
                      - message
                    additionalProperties: false
                required:
                  - error
                additionalProperties: false
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-coderabbitai-api-key
      description: >-
        See [Authentication](/api/authentication) for the key types and where to
        create a key.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.