---
title: "Create environment"
method: POST
path: "/v1/projects/{project_id}/environments"
tags: ["environments"]
---

# Create environment

`POST /v1/projects/{project_id}/environments`

## Request

- Base URL: `https://api.connic.co`
- URL: `https://api.connic.co/v1/projects/{project_id}/environments`
- Auth: HTTP bearer

Create an environment. The project's first environment becomes the default.

Returns 403 when the plan's environment limit is reached. With `copy_from_environment_id`,
that environment's variables are copied into the new one.

Required permission: `environments.create`. Passing `copy_from_environment_id` also requires `variables.view`. Passing `copy_from_environment_id` also requires `variables.create`.

## Path parameters

- `project_id` string, uuid, required

## Request body

- EnvironmentCreate
  - `log_retention_seconds` integer, nullable: How long runs are kept before automatic deletion, in seconds. At most the plan's retention; null uses the plan's retention.
  - `redacted_keys` string[]: JSON field paths, such as `user.token` or `*.password`, whose values are replaced with `[REDACTED]` in newly recorded run data, logs and traces. Defaults to common secret field names.
  - `manual_deploy_group_ids` string[], nullable: Permission group IDs whose members can start deployments manually in this environment. null allows all groups; an empty list allows only the project owner.
  - `copy_from_group_ids` string[], nullable: Permission group IDs whose members can copy data from this environment into another. null allows all groups; an empty list allows only the project owner.
  - `name` string, required: Display name. Its slug must be unique among the project's environments.
  - `git_branch` string, nullable: Git branch whose pushes deploy to this environment. null for projects that deploy with the CLI.
  - `copy_from_environment_id` string, uuid, nullable: ID of an environment whose variables are copied into the new one. Copying also requires `variables.view` and `variables.create`.
  - `pr_testing_enabled` boolean, nullable: Run the test suite when a pull request targets `git_branch`. Pro and enterprise plans only. Defaults to true when `git_branch` is set, a git provider is connected and the plan allows it.
  - `deploy_gate_tests_enabled` boolean, nullable: Run the test suite before each deployment in this environment is activated. Defaults to true.

## Response `201`

Successful Response

- PublicEnvironmentResponse
  - `id` string, uuid, required
  - `project_id` string, uuid, required: Project the environment belongs to.
  - `name` string, required
  - `slug` string, required: URL-safe identifier derived from `name`, unique within the project.
  - `git_branch` string, nullable, required: Git branch this environment deploys from. Null when deployments come from CLI uploads.
  - `is_active` boolean, required: Whether the environment is active. Git pushes and pull request tests only target active environments.
  - `is_default` boolean, required: Whether this is the project's default environment. A project has exactly one.
  - `env_type` string, required: `standard` for regular environments, `test` for dev environments created by `connic dev`.
  - `is_ephemeral` boolean, required: True for dev environments that are deleted when their `connic dev` session ends.
  - `test_environment_id` string, uuid, nullable, required: Environment the test suite runs in for deploy gate and pull request tests. Null runs the tests in this environment.
  - `pr_testing_enabled` boolean, required: Whether the test suite runs for pull requests that target `git_branch`.
  - `deploy_gate_tests_enabled` boolean, required: Whether deployments run the test suite before activating. A failing case stops the deployment.
  - `log_retention_seconds` integer, nullable, required: How long run data is kept, in seconds. Null applies the plan's default retention.
  - `log_retention_max_seconds` integer, nullable, required: Longest retention the project's plan allows, in seconds. Null means no limit.
  - `redacted_keys` string[], required: Dot-separated JSON paths whose values are replaced with `[REDACTED]` in stored run data, traces and connector logs. A leading `*` matches at any depth, as in `*.password`.
  - `manual_deploy_group_ids` string[], nullable, required: Permission groups whose members can deploy to this environment manually. Null allows everyone with deploy permission; an empty list allows only the project owner.
  - `copy_from_group_ids` string[], nullable, required: Permission groups whose members can copy from this environment into other environments. Null allows everyone; an empty list allows only the project owner.
  - `can_copy_from` boolean, required: Whether the caller can use this environment as a copy source. Always false for dev environments.
  - `can_deploy` boolean, required: Whether the caller can deploy to this environment manually.
  - `can_use_dev_session` boolean, required: Whether the caller can run a `connic dev` session in this environment. Only dev environments allow it.
  - `created_at` string, date-time, required
  - `updated_at` string, date-time, required
  - `deleted_at` string, date-time, nullable, required: Always null, because deleted environments are not returned.

## Other responses

- `401`: Missing or invalid API key.
- `403`: The API key lacks the required permission or access to the environment.
- `422`: Validation Error
- `429`: Rate limit exceeded.

---

[API](https://skmtc.dev/connic/apis/connic-api.md) · [All operations](https://skmtc.dev/connic/apis/connic-api/llms.txt) · [OpenAPI document](https://skmtc.dev/connic/apis/connic-api/revisions/482932da5fbe?raw)
