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

# Administration API: Environments

> Create, update, and delete Bolt and agent environments, set the default of each type, and set what an agent environment defers to with the Administration API.

Manage a workspace's environments from code: create Bolt and agent environments, change their name, branch and dbt™ version, choose the default of each type, set what an agent environment defers to, and delete environments.

> [!NOTE]
>
> **Prerequisites:**
>
> * These operations are part of the Enterprise plan. On other plans, they fail with `PLAN_UPGRADE_REQUIRED`.
> * An account API key with the `X-Paradime-Workspace` header, or a workspace API key.
> * The **Environment admin** capability group. To read `Environment.discovery`, the key also needs **Discovery API viewer**. To read `Environment.deferSchedule`, it also needs **Bolt admin** or another group with `bolt:schedules:list`.
>
> Keys, errors, and pagination work the same in every area. See [Conventions](https://docs.paradime.io/developers/graphql-api/admin-api/conventions.md).

## Operations

| Operation | Type | What it does | Capability group |
| - | - | - | - |
| [`Workspace.environments`](https://docs.paradime.io/graphql-reference/types/Workspace) | Field | Lists the workspace's Bolt and agent environments, ordered by slug. | Environment admin |
| [`Environment.variableNames`](https://docs.paradime.io/graphql-reference/types/Environment) | Field | Reads the names of an environment's variables, never the values. | Environment admin |
| [`Environment.hasWarehouseConnection`](https://docs.paradime.io/graphql-reference/types/Environment) | Field | Reads whether the environment has a saved warehouse connection. | Environment admin |
| [`Environment.discovery`](https://docs.paradime.io/graphql-reference/types/Environment) | Field | Reads a Bolt environment's [Discovery API](https://docs.paradime.io/developers/graphql-api/api-reference/discovery-api) data. | Discovery API viewer |
| [`createEnvironment`](https://docs.paradime.io/graphql-reference/mutations/createEnvironment) | Mutation | Creates a Bolt or agent environment. | Environment admin |
| [`updateEnvironment`](https://docs.paradime.io/graphql-reference/mutations/updateEnvironment) | Mutation | Changes an environment's name, branch, or dbt™ version. | Environment admin |
| [`deleteEnvironment`](https://docs.paradime.io/graphql-reference/mutations/deleteEnvironment) | Mutation | Deletes an environment with its warehouse connections and variables. | Environment admin |
| [`setDefaultEnvironment`](https://docs.paradime.io/graphql-reference/mutations/setDefaultEnvironment) | Mutation | Makes an environment the default of its type. | Environment admin |
| [`setAgentEnvironmentDeferTarget`](https://docs.paradime.io/graphql-reference/mutations/setAgentEnvironmentDeferTarget) | Mutation | Sets what an agent environment's runs defer to: a Bolt environment, a Bolt schedule, or nothing. | Environment admin |

## Environment types and slugs

An environment's `type` is `SCHEDULER` for a Bolt environment, where scheduled runs execute, or `AGENT` for an agent environment, where DinoAI agent runs execute. Each type has one default environment: runs of that type use it when they name no environment.

Every environment has a `slug`, unique in its workspace, and the slug never changes. The operations on this page name an environment by its slug. A slug is lowercase letters and digits in groups joined by single hyphens, at most 80 characters, and is not `production`.

Older workspaces have a built-in Bolt environment with the slug `production`. A new workspace, such as one from `createWorkspace`, gets a default Bolt environment and a default agent environment with generated slugs. Read `environments` to find the slugs.

## Create an environment

`createEnvironment` creates an environment in the workspace that the key targets. A new agent environment defers to the default Bolt environment.

* `name` is the display name.
* `slug` is optional. Send your own slug to make the call safe to retry: sending the same input again returns the same environment, and the same slug with other settings is a `CONFLICT`. Without a slug, Paradime generates one, and every call creates another environment.
* `branch` is the git branch its runs use. Leave it out for the workspace's default branch.
* `dbtVersion` is one of the workspace's `supportedDbtVersions`. Leave it out to follow the workspace's dbt™ version.

```graphql theme={"system"}
mutation CreateEnvironment($input: CreateEnvironmentInput!) {
  createEnvironment(input: $input) {
    environment {
      slug
      type
      name
      isDefault
      branch
      dbtVersion
      deferEnvironment {
        slug
      }
    }
  }
}
```

```json theme={"system"}
{
  "input": {
    "type": "SCHEDULER",
    "name": "Staging",
    "slug": "staging",
    "branch": "develop"
  }
}
```

> [accordion] Example response
>
> ```json theme={"system"}
> {
>   "data": {
>     "createEnvironment": {
>       "environment": {
>         "slug": "staging",
>         "type": "SCHEDULER",
>         "name": "Staging",
>         "isDefault": false,
>         "branch": "develop",
>         "dbtVersion": null,
>         "deferEnvironment": null
>       }
>     }
>   }
> }
> ```

Then add its warehouse connection with [`createWarehouseConnection`](https://docs.paradime.io/developers/graphql-api/admin-api/warehouse-connections#create-a-connection), and its variables with [`setEnvironmentVariables`](https://docs.paradime.io/developers/graphql-api/admin-api/environment-variables).

## List environments

`environments` lists the workspace's environments, ordered by slug. Pass `type` to list only one type.

```graphql theme={"system"}
query ListEnvironments($type: EnvironmentType) {
  workspace {
    environments(type: $type) {
      totalCount
      edges {
        node {
          slug
          type
          name
          isDefault
          branch
          dbtVersion
          hasWarehouseConnection
          variableNames
          deferEnvironment {
            slug
          }
        }
      }
    }
  }
}
```

```json theme={"system"}
{ "type": "AGENT" }
```

`deferEnvironment` is `null` when the agent environment defers to a schedule or to nothing. `deferSchedule` is `null` when it defers to an environment or to nothing.

To read a Bolt environment's Discovery API data, select `discovery`. It returns the same data as the root [`environment(slug:)`](https://docs.paradime.io/graphql-reference/queries/environment) query, and it is `null` for an agent environment.

## Change an environment

`updateEnvironment` changes only the settings that you send:

* `name`: a new display name. It can't be `null`.
* `branch`: the git branch its runs use. `null` sets the workspace's default branch.
* `dbtVersion`: the dbt™ version its runs use. `null` follows the workspace's dbt™ version. Changing a Bolt environment's version redeploys the workspace's Bolt schedules.

```graphql theme={"system"}
mutation UpdateEnvironment($input: UpdateEnvironmentInput!) {
  updateEnvironment(input: $input) {
    environment {
      slug
      name
      branch
      dbtVersion
    }
  }
}
```

```json theme={"system"}
{
  "input": {
    "slug": "staging",
    "name": "Staging",
    "dbtVersion": "1.11"
  }
}
```

To make an environment the default of its type, call `setDefaultEnvironment`:

```graphql theme={"system"}
mutation SetDefaultEnvironment($input: SetDefaultEnvironmentInput!) {
  setDefaultEnvironment(input: $input) {
    environment {
      slug
      isDefault
    }
  }
}
```

```json theme={"system"}
{ "input": { "slug": "staging" } }
```

## Set what an agent environment defers to

An agent environment's runs defer to the most recent run of a Bolt environment, or to the runs of one Bolt schedule. In `deferTo`, set exactly one of `environmentSlug` and `scheduleSlug`. Send `deferTo: null` to clear the target. Only an agent environment has a defer target.

```graphql theme={"system"}
mutation SetDeferTarget($input: SetAgentEnvironmentDeferTargetInput!) {
  setAgentEnvironmentDeferTarget(input: $input) {
    environment {
      slug
      deferEnvironment {
        slug
      }
      deferSchedule {
        slug
      }
    }
  }
}
```

```json theme={"system"}
{
  "input": {
    "slug": "agents",
    "deferTo": { "environmentSlug": "staging" }
  }
}
```

## Delete an environment

`deleteEnvironment` deletes an environment with its warehouse connections and variables. Its slug is free to use again. Deleting it again is not an error.

> [!WARNING]
>
> You can't delete the built-in `production` environment, the default environment of a type, or a Bolt environment that an agent environment defers to. Make another environment the default, or point the agent environments elsewhere, first.

```graphql theme={"system"}
mutation DeleteEnvironment($input: DeleteEnvironmentInput!) {
  deleteEnvironment(input: $input) {
    environment {
      slug
      type
    }
  }
}
```

```json theme={"system"}
{ "input": { "slug": "staging" } }
```

## Errors

These are the cases specific to environments. For the error format and the codes every area shares, see [Errors](https://docs.paradime.io/developers/graphql-api/admin-api/conventions.md#errors).

| Code | When |
| - | - |
| `CONFLICT` | An environment with the slug exists with other settings, on create. A Bolt and an agent environment have the same slug. You try to delete `production`, a default environment, or a Bolt environment that an agent environment defers to. |
| `NOT_FOUND` | The workspace has no environment with the slug. The `deferTo` target is not a Bolt environment or a Bolt schedule of the workspace. |
| `VALIDATION_FAILED` | The slug breaks the slug rule. The name is blank, or `null` on update. The `dbtVersion` is not one your account can use. `deferTo` sets both fields or neither. The environment of `setAgentEnvironmentDeferTarget` is not an agent environment. |

## Related

* [Python SDK: Environments](https://docs.paradime.io/developers/python-sdk/modules/admin/environments.md): the same operations in `paradime.admin.environments`.
* [Paradime CLI: `paradime admin`](https://docs.paradime.io/developers/paradime-cli/admin-cli): `paradime admin environments` lists, creates, updates, and deletes environments, and sets the default and the defer target.
* [Create and manage environments](https://docs.paradime.io/products/settings/connections/index.md#create-and-manage-environments): the same settings in the app.
* [Agent environment: defer to a previous run](https://docs.paradime.io/products/settings/connections/dinoai-background-agent-environment/index.md#defer-to-a-previous-run): how agents use the defer target.
* [Administration API: Warehouse connections](https://docs.paradime.io/developers/graphql-api/admin-api/warehouse-connections) and [Environment variables](https://docs.paradime.io/developers/graphql-api/admin-api/environment-variables): what each environment holds.


## Related topics

- [Administration API: Environment variables](https://docs.paradime.io/developers/graphql-api/admin-api/environment-variables.md)
- [Administration API: Bolt](https://docs.paradime.io/developers/graphql-api/admin-api/bolt.md)
- [Administration API: Warehouse connections](https://docs.paradime.io/developers/graphql-api/admin-api/warehouse-connections.md)
- [Administration API](https://docs.paradime.io/developers/graphql-api/admin-api/index.md)
- [Administration API: Conventions](https://docs.paradime.io/developers/graphql-api/admin-api/conventions.md)


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