---
title: create-a-custom-environment-for-the-current-project
product: vercel
url: /docs/rest-api/environment/create-a-custom-environment-for-the-current-project
type: reference
prerequisites:
  []
related:
  - /docs/rest-api
summary: Learn about create-a-custom-environment-for-the-current-project on Vercel.
install_vercel_plugin: npx plugins add vercel/vercel-plugin
---

# Create a custom environment for the current project.

```http
POST /v9/projects/{idOrName}/custom-environments
```

Creates a custom environment for the current project. Cannot be named 'Production' or 'Preview'.

## Authentication

**bearerToken**: HTTP bearer

## Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `idOrName` | string | Yes | The unique project identifier or the project name |


## Query parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `teamId` | string | No | The Team identifier to perform the request on behalf of. |
| `slug` | string | No | The Team slug to perform the request on behalf of. |


## Request body

Required: No

Content-Type: `application/json`

```json
{
  "type": "object",
  "properties": {
    "slug": {
      "type": "string",
      "description": "The slug of the custom environment to create.",
      "maxLength": 32
    },
    "description": {
      "type": "string",
      "description": "Description of the custom environment. This is optional.",
      "maxLength": 256
    },
    "branchMatcher": {
      "type": "object",
      "description": "How we want to determine a matching branch. This is optional.",
      "required": [
        "type",
        "pattern"
      ],
      "properties": {
        "type": {
          "description": "Type of matcher. One of \\\"equals\\\", \\\"startsWith\\\", or \\\"endsWith\\\".",
          "enum": [
            "equals",
            "startsWith",
            "endsWith"
          ]
        },
        "pattern": {
          "type": "string",
          "description": "Git branch name or portion thereof.",
          "maxLength": 100
        }
      }
    },
    "copyEnvVarsFrom": {
      "type": "string",
      "description": "Where to copy environment variables from. This is optional."
    }
  }
}
```

## Responses

### 201: No description

Content-Type: `application/json`

```json
{
  "type": "object",
  "description": "Internal representation of a custom environment with all required properties",
  "required": [
    "createdAt",
    "id",
    "slug",
    "type",
    "updatedAt"
  ],
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique identifier for the custom environment (format: env_*)"
    },
    "slug": {
      "type": "string",
      "description": "URL-friendly name of the environment"
    },
    "type": {
      "type": "string",
      "description": "The type of environment (production, preview, or development)",
      "enum": [
        "production",
        "preview",
        "development"
      ]
    },
    "description": {
      "type": "string",
      "description": "Optional description of the environment's purpose"
    },
    "branchMatcher": {
      "type": "object",
      "description": "Configuration for matching git branches to this environment",
      "required": [
        "pattern",
        "type"
      ],
      "properties": {
        "type": {
          "type": "string",
          "description": "The type of matching to perform",
          "enum": [
            "endsWith",
            "startsWith",
            "equals"
          ]
        },
        "pattern": {
          "type": "string",
          "description": "The pattern to match against branch names"
        }
      }
    },
    "domains": {
      "type": "array",
      "description": "List of domains associated with this environment",
      "items": {
        "type": "object",
        "description": "List of domains associated with this environment",
        "required": [
          "apexName",
          "name",
          "projectId",
          "verified"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "apexName": {
            "type": "string"
          },
          "projectId": {
            "type": "string"
          },
          "redirect": {
            "type": "string",
            "nullable": true
          },
          "redirectStatusCode": {
            "type": "number",
            "enum": [
              301,
              302,
              307,
              308
            ],
            "nullable": true
          },
          "gitBranch": {
            "type": "string",
            "nullable": true
          },
          "customEnvironmentId": {
            "type": "string",
            "nullable": true
          },
          "updatedAt": {
            "type": "number"
          },
          "createdAt": {
            "type": "number"
          },
          "verified": {
            "type": "boolean",
            "description": "`true` if the domain is verified for use with the project. If `false` it will not be used as an alias on this project until the challenge in `verification` is completed.",
            "enum": [
              false,
              true
            ]
          },
          "verification": {
            "type": "array",
            "description": "A list of verification challenges, one of which must be completed to verify the domain for use on the project. After the challenge is complete `POST /projects/:idOrName/domains/:domain/verify` to verify the domain. Possible challenges: - If `verification.type = TXT` the `verification.domain` will be checked for a TXT record matching `verification.value`.",
            "items": {
              "type": "object",
              "description": "A list of verification challenges, one of which must be completed to verify the domain for use on the project. After the challenge is complete `POST /projects/:idOrName/domains/:domain/verify` to verify the domain. Possible challenges: - If `verification.type = TXT` the `verification.domain` will be checked for a TXT record matching `verification.value`.",
              "required": [
                "domain",
                "reason",
                "type",
                "value"
              ],
              "properties": {
                "type": {
                  "type": "string"
                },
                "domain": {
                  "type": "string"
                },
                "value": {
                  "type": "string"
                },
                "reason": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "currentDeploymentAliases": {
      "type": "array",
      "description": "List of aliases for the current deployment",
      "items": {
        "type": "string"
      }
    },
    "createdAt": {
      "type": "number",
      "description": "Timestamp when the environment was created"
    },
    "updatedAt": {
      "type": "number",
      "description": "Timestamp when the environment was last updated"
    }
  }
}
```

### 400: One of the provided values in the request body is invalid.
One of the provided values in the request query is invalid.

### 401: The request is not authorized.

### 402: The account was soft-blocked for an unhandled reason.
The account is missing a payment so payment method must be updated

### 403: You do not have permission to access this resource.

### 500: No description

---

## Related

- [environment endpoints](/docs/rest-api#environment)

- [REST API overview](/docs/rest-api)

- [OpenAPI spec](https://openapi.vercel.sh/) (machine-readable, all endpoints)

---

[View full sitemap](/docs/sitemap)
