---
title: "Create a new environment variable"
method: POST
path: "/projects/{project_id}/env-vars"
tags: ["Projects"]
---

# Create a new environment variable

`POST /projects/{project_id}/env-vars`

## Request

- Base URL: `/api` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/projects/{project_id}/env-vars`
- Auth: HTTP bearer

## Path parameters

- `project_id` integer, required

## Request body

- CreateEnvironmentVariableRequest
  - `environment_ids` integer[], required
  - `include_in_preview` boolean: Include this environment variable in preview environments (default: false)
  - `is_secret` boolean: When true the stored value is write-only: it is omitted from API responses and cannot be revealed, even by an administrator. Updates that omit the value preserve the existing ciphertext. The flag is one-way — secret vars cannot be demoted to regular vars.
  - `key` string, required
  - `value` string, required

## Response `201`

Environment variables created successfully

- EnvironmentVariableResponse
  - `created_at` string, date-time, required
  - `environments` EnvironmentInfo[], required
    - `current_deployment_id` integer, nullable
    - `id` integer, required
    - `main_url` string, required
    - `name` string, required
  - `id` integer, required
  - `include_in_preview` boolean, required: Include this environment variable in preview environments
  - `is_secret` boolean, required: Whether the stored value is write-only. Marked secrets always have `value: None` in API responses and cannot be revealed.
  - `key` string, required
  - `secret_suggestion` SecretSuggestionResponse, nullable: Why a regular environment variable should probably be a secret.
    - `message` string, required: One sentence for the operator, e.g. "DATABASE_URL contains a password in its connection string".
    - `reason` 'connection_string_password' | 'private_key' | 'provider_token' | 'json_web_token' | 'credential_name', required: Why a regular variable looks like it holds a credential.
  - `updated_at` string, date-time, required
  - `value` string, nullable: Plaintext for regular variables in create/update responses, or `"***"` in list responses. Always `None` for marked secrets. Only regular variables can be read through the audited per-variable reveal endpoint.

## Other responses

- `400`: Invalid input
- `404`: Project not found
- `500`: Internal server error

## Changes

- **2026-11-26** `e1864d950604`: 2 breaking
  - the `created_at` response's property type changed from `integer` to `string`, and format from `int64` to `date-time` for status `201`
  - the `updated_at` response's property type changed from `integer` to `string`, and format from `int64` to `date-time` for status `201`
- **2026-11-25** `480a86944327`: 1 info
  - the endpoint scheme security `bearer_auth` was added to the API
- **2026-11-01** `d73a147552a5`: 1 info
  - added the optional property `secret_suggestion` to the response with the `201` status
- **2026-09-07** `cdc1afae1752`: 1 info
  - the `include_in_preview` request property default value `false` was added
- **2026-09-07** `f7404eb7ac98`: 1 info
  - the `include_in_preview` request property default value `false` was removed

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/projects/:project_id/env-vars/post.md)

---

[API](https://skmtc.dev/gotempsh/apis/temps.md) - [All operations](https://skmtc.dev/gotempsh/apis/temps/llms.txt) - [OpenAPI document](https://skmtc.dev/gotempsh/apis/temps/revisions/3b040526eb43?raw)
