---
title: "Create a new secret. The value is encrypted before storage and will be mounted as a file at `/run/secrets/<KEY>` on the next deployment. The plaintext value is NOT returned — the response carries only metadata."
method: POST
path: "/projects/{project_id}/secrets"
tags: ["Secrets"]
---

# Create a new secret. The value is encrypted before storage and will be mounted as a file at \`/run/secrets/<KEY>\` on the next deployment. The plaintext value is NOT returned — the response carries only metadata.

`POST /projects/{project_id}/secrets`

## 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}/secrets`
- Auth: HTTP bearer

## Path parameters

- `project_id` integer, required

## Request body

- CreateProjectSecretRequest: Request to create a new project secret. Project secrets are mounted into the container as files under `/run/secrets/<KEY>` as a read-only mount, instead of as environment variables, so they do not appear in `docker inspect`. Values are always encrypted at rest and never returned in plaintext from the API after create. Distinct from agent secrets (global `/settings/secrets`).
  - `compose_services` string[]: Docker Compose services allowed to read this secret, by compose service name. Empty (the default) delivers it to every service in the stack, which is how secrets behaved before scoping existed. Ignored by non-Compose presets: those deploy a single container, which always receives every secret in scope for its environment.
  - `environment_ids` integer[]
  - `include_in_preview` boolean: Include this secret in preview environments (default: false).
  - `key` string, required: Identifier for the secret. Becomes the filename at `/run/secrets/<KEY>`. Must start with a letter or underscore and contain only A-Z, a-z, 0-9, _.
  - `value` string, required: Plaintext value, <= 1 MiB.

## Response `201`

Secret created

- ProjectSecretResponse: Project secret metadata. There is deliberately no `value` field — secret plaintext is never returned after creation. Callers that need the value must read it from the mounted file inside the container.
  - `compose_services` string[], required: Compose services this secret is restricted to. Empty means every service in the stack.
  - `created_at` string, date-time, required
  - `environments` ProjectSecretEnvironmentInfo[], required
    - `id` integer, required
    - `main_url` string, required
    - `name` string, required
  - `id` integer, required
  - `include_in_preview` boolean, required
  - `key` string, required
  - `project_id` integer, required
  - `updated_at` string, date-time, required

## Other responses

- `400`: Invalid key or value too large
- `409`: Key already exists in project
- `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-09-07** `cdc1afae1752`: 3 info
  - added the new optional request property `compose_services`
  - the `include_in_preview` request property default value `false` was added
  - added the required property `compose_services` to the response with the `201` status
- **2026-09-07** `f7404eb7ac98`: 1 breaking, 1 warning, 1 info
  - removed the required property `compose_services` from the response with the `201` status
  - removed the request property `compose_services`
  - the `include_in_preview` request property default value `false` was removed
- **2026-08-17** `bd326cf0ea13`: 2 info
  - added the new optional request property `compose_services`
  - added the required property `compose_services` to the response with the `201` status

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/projects/:project_id/secrets/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)
