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

# Environments

> Create and manage environments for your Stormkit applications

The Environments API allows you to programmatically create and delete environments within your applications.

## Create Environment

<ParamField path="POST /v1/env" type="endpoint">
  Create a new environment for an application.
</ParamField>

<Note>
  Requires an application or team level API key.
</Note>

### Request Body

<ParamField body="appId" type="number" required>
  The application ID
</ParamField>

<ParamField body="name" type="string" required>
  The environment name
</ParamField>

<ParamField body="branch" type="string" required>
  The default Git branch for this environment
</ParamField>

<ParamField body="autoDeploy" type="boolean" default="false">
  Enable automatic deployments
</ParamField>

<ParamField body="autoPublish" type="boolean" default="false">
  Automatically publish new deployments
</ParamField>

<ParamField body="buildCmd" type="string">
  The build command (e.g., "npm run build")
</ParamField>

<ParamField body="distFolder" type="string">
  The output folder containing build assets
</ParamField>

<ParamField body="envVars" type="object">
  Environment variables as key-value pairs
</ParamField>

<ParamField body="apiFolder" type="string">
  The folder containing serverless API functions
</ParamField>

<ParamField body="autoDeployBranches" type="string">
  Regex/glob pattern to filter branches for auto-deployment
</ParamField>

<ParamField body="autoDeployCommits" type="string">
  Regex/glob pattern to filter commits for auto-deployment
</ParamField>

<ParamField body="errorFile" type="string">
  Custom error page file path (must be in distFolder)
</ParamField>

<ParamField body="headersFile" type="string">
  Path to custom headers file
</ParamField>

<ParamField body="redirectsFile" type="string">
  Path to custom redirects file
</ParamField>

<ParamField body="previewLinks" type="boolean">
  Enable preview links on pull/merge requests
</ParamField>

<ParamField body="serverCmd" type="string">
  Server command for running the application (self-hosted only)
</ParamField>

<ParamField body="statusChecks" type="array">
  Post-deployment status check commands

  <Expandable title="Status Check Object">
    <ParamField body="name" type="string" required>
      Status check name
    </ParamField>

    <ParamField body="cmd" type="string" required>
      Command to execute
    </ParamField>

    <ParamField body="description" type="string">
      Status check description
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="redirects" type="array">
  Array of redirect rules (see [Redirects API](/api/redirects))
</ParamField>

### Response

<ResponseField name="envId" type="string">
  The ID of the newly created environment
</ResponseField>

<CodeGroup>
  ```bash Request theme={null}
  curl -X POST \
    -H 'Authorization: <api_key>' \
    -H 'Content-Type: application/json' \
    'https://api.stormkit.io/v1/env' \
    -d '{
      "appId": 1510,
      "branch": "main",
      "name": "production",
      "autoDeploy": true,
      "autoPublish": true,
      "buildCmd": "npm run build",
      "distFolder": "dist",
      "envVars": {
        "NODE_ENV": "production",
        "API_URL": "https://api.example.com"
      }
    }'
  ```

  ```json Response theme={null}
  {
    "envId": "5061"
  }
  ```
</CodeGroup>

***

## Delete Environment

<ParamField path="DELETE /v1/env" type="endpoint">
  Delete an environment by its ID.
</ParamField>

### Query Parameters

<ParamField query="id" type="string" required>
  The environment ID to delete
</ParamField>

### Response

<ResponseField name="ok" type="boolean">
  Whether the deletion was successful
</ResponseField>

<CodeGroup>
  ```bash Request theme={null}
  curl -X DELETE \
    -H 'Authorization: <api_key>' \
    -H 'Content-Type: application/json' \
    'https://api.stormkit.io/v1/env?id=5061'
  ```

  ```json Response theme={null}
  {
    "ok": true
  }
  ```
</CodeGroup>

***

## Environment Configuration

Environments in Stormkit support various configuration options:

### Auto-Deploy Settings

Control which branches and commits trigger automatic deployments:

* **autoDeployBranches**: Use glob patterns like `feature/*` or regex patterns to match branch names
* **autoDeployCommits**: Filter commits by message pattern

### Build Configuration

* **buildCmd**: The command executed during the build phase
* **distFolder**: Where your static assets are output after build
* **apiFolder**: Location of serverless functions

### Custom Files

* **errorFile**: Custom 404/error page
* **headersFile**: Custom HTTP headers configuration
* **redirectsFile**: Custom redirects and rewrites

<Tip>
  For detailed information about redirects and path rewrites, see the [Redirects API documentation](/api/redirects).
</Tip>
