# Upsert an env entry

PUT

/v1/env/{name}

```sh
curl --request PUT \
  --url 'https://example.com/v1/env/example?envName=example&scopeKind=tenant' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{ "scope": { "kind": "tenant", "tenantId": "example" }, "envName": "example", "name": "example", "value": "example", "tags": { "additionalProperty": "example" }, "ifRevision": 1 }'
```

Requires the `env:write` capability. Every write bumps `revision`; optional `ifRevision` guards against concurrent updates (409 `env-write-conflict`). Env values aren’t secret: they’re recorded with each run that uses them. A credential goes in `/v1/secrets`. A body with `cloudSecret` is refused: only the operator sets a name to a cloud secret, with a system key.

## Authorizations

- **[bearerAuth](https://docs.kindgi.com/reference/api.md#bearerauth)**

## Parameters

### Path Parameters

**name**

required

string

\>= 1 characters

Env entry name (opaque string within the workspace + envName).

### Query Parameters

**envName**

required

Per-environment slug. `[a-z][a-z0-9-]{0,62}` — RFC-1035-like label.

string

/^\[a-z]\[a-z0-9-]{0,62}$/

`[a-z][a-z0-9-]{0,62}`. Required on every env + secrets route.

**scopeKind**

required

Discriminator for the ?scopeKind + ?scopeId + ?inherit triplet. Tenant carries no id (implicit from session); org/project require scopeId.

string

Allowed values: tenant org project

Required on every env + secrets route. Tenant carries no `scopeId`; org / project require `scopeId`.

**scopeId**

string

\>= 1 characters

Required IF scopeKind is `org` or `project`. MUST be absent if scopeKind=`tenant` (the workspace is implicit from the session). Malformed combinations return 400 scope-invalid.

### Header Parameters

**Idempotency-Key**

string

\>= 1 characters

Caller-supplied idempotency key, scoped to the caller: the same key from someone else in the workspace is their own request (from 0.1.5). Retries with the same key return the original response byte-identical (per `docs/API-ROUTE-CONVENTIONS.md` §3.1). A retry sent while the first request still runs is answered `409 idempotency-key-in-flight` with `Retry-After`, on a runtime whose store holds keys (from 0.1.5); retry after it, and you get the first request’s answer. An answer that carries a secret (a new API key or public run token, a session token, a generated signing secret) isn’t kept: a retry gets `409 idempotency-key-replay-withheld`, with the first request’s status and when it succeeded (from 0.1.5). A request whose key store can’t be read before it runs is answered `503 idempotency-store-unavailable` with `Retry-After`: nothing ran, so retry with the same key (from 0.3.0).

## Request Bodyrequired

application/json

object

**scope**

One of:

- **object**

  object

  **kind**

  required

  string

  Allowed values: tenant

  **tenantId**

  required

  string

- **object**

  object

  **kind**

  required

  string

  Allowed values: org

  **tenantId**

  required

  string

  **orgId**

  required

  string

- **object**

  object

  **kind**

  required

  string

  Allowed values: project

  **tenantId**

  required

  string

  **projectId**

  required

  string

**envName**

Per-environment slug. `[a-z][a-z0-9-]{0,62}` — RFC-1035-like label.

string

/^\[a-z]\[a-z0-9-]{0,62}$/

**name**

string

\>= 1 characters

**value**

required

string

**tags**

object

**_key_**

additional properties

string

**ifRevision**

integer

## Responses

### 200

Env record.

application/json

object

**scope**

required

One of:

- **object**

  object

  **kind**

  required

  string

  Allowed values: tenant

  **tenantId**

  required

  string

- **object**

  object

  **kind**

  required

  string

  Allowed values: org

  **tenantId**

  required

  string

  **orgId**

  required

  string

- **object**

  object

  **kind**

  required

  string

  Allowed values: project

  **tenantId**

  required

  string

  **projectId**

  required

  string

**envName**

required

Per-environment slug. `[a-z][a-z0-9-]{0,62}` — RFC-1035-like label.

string

/^\[a-z]\[a-z0-9-]{0,62}$/

**name**

required

string

**value**

required

string

**revision**

required

integer

**createdAt**

required

string format: date-time

**updatedAt**

required

string format: date-time

**tags**

object

**_key_**

additional properties

string

##### Example

```json
{
  "scope": {
    "kind": "tenant"
  }
}
```

### 400

Malformed request body.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 401

Missing / malformed / expired / revoked bearer token.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 403

Bearer token missing `env:write` capability; or a body with `cloudSecret`, which only the operator sets (`cloud-secret-system-only`). Without an authorization store, `key-project-mismatch` (`details.keyProjectId`): the API key or session is limited to a project, and this writes above it, to the workspace, an org or a team (with a store, that is `permission-denied`).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 409

`ifRevision` mismatch (env-write-conflict). Or `env-not-served`: this runtime keeps every value under the env it serves (whoami’s `servedEnv`, with `refusesOtherEnvs`), so a value under another env would never be read. `details.envName` is the env asked for, `details.servedEnv` the one to use. A secret that a provider, MCP endpoint or webhook endpoint registered before names under that env, at the scope it’s read at, is still written: it’s read there. Nothing is stored otherwise. Or `idempotency-key-in-flight` (with `Retry-After`): a request with the same `Idempotency-Key` still runs, so this one wasn’t run; send it again after `Retry-After` to get that request’s answer.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

#### Headers

**Retry-After**

integer

\>= 1

Whole seconds to wait before sending the request again, at least 1. Sent with the codes the answer names as sending it, so it may be absent.

### 413

The request body is over the API’s limit (`request-too-large`; `details.maxBytes` says how much).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 429

`rate-limit-exceeded` with `details.limit: "api-requests"`, on a runtime that sets workspace limits (Kindgi Cloud): this workspace’s limit on API requests a minute is reached, so the request wasn’t run; `Retry-After` says when to send it again.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

#### Headers

**Retry-After**

integer

\>= 1

Whole seconds to wait before sending the request again, at least 1. Sent with the codes the answer names as sending it, so it may be absent.

### 500

Server error (unmapped domain code or framework crash).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 501

A body with `cloudSecret`, on a runtime that keeps no cloud secrets (`cloud-secrets-unsupported`).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 503

The `Idempotency-Key` store (`idempotency-store-unavailable`) or the authorization store (`authz-backend-unavailable`) couldn’t be reached before the request ran, or the database was too busy for its authorization check (`database-busy`), so nothing was changed; `Retry-After` (whole seconds) says when to try again with the same key. Or `tenant-state-unavailable` (with `Retry-After`), on a runtime serving many workspaces: the workspace’s state couldn’t be read, so nothing was changed.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

#### Headers

**Retry-After**

integer

\>= 1

Whole seconds to wait before sending the request again, at least 1. Sent with the codes the answer names as sending it, so it may be absent.

## See also

- [`GET /v1/env/{name}`: Get one env entry](https://docs.kindgi.com/reference/api/operations/envget.md)
- [`DELETE /v1/env/{name}`: Delete an env entry](https://docs.kindgi.com/reference/api/operations/envdelete.md)
- [Error code `authz-backend-unavailable`](https://docs.kindgi.com/reference/errors.md#authz-backend-unavailable)
- [Error code `cloud-secret-system-only`](https://docs.kindgi.com/reference/errors.md#cloud-secret-system-only)
- [Error code `cloud-secrets-unsupported`](https://docs.kindgi.com/reference/errors.md#cloud-secrets-unsupported)
- [Error code `database-busy`](https://docs.kindgi.com/reference/errors.md#database-busy)
- [Error code `env-not-served`](https://docs.kindgi.com/reference/errors.md#env-not-served)
- [Error code `idempotency-key-in-flight`](https://docs.kindgi.com/reference/errors.md#idempotency-key-in-flight)
- [Error code `idempotency-store-unavailable`](https://docs.kindgi.com/reference/errors.md#idempotency-store-unavailable)
- [Error code `key-project-mismatch`](https://docs.kindgi.com/reference/errors.md#key-project-mismatch)
- [Error code `permission-denied`](https://docs.kindgi.com/reference/errors.md#permission-denied)
- [Error code `rate-limit-exceeded`](https://docs.kindgi.com/reference/errors.md#rate-limit-exceeded)
- [Error code `request-too-large`](https://docs.kindgi.com/reference/errors.md#request-too-large)
- [Error code `tenant-state-unavailable`](https://docs.kindgi.com/reference/errors.md#tenant-state-unavailable)
- [Every error code](https://docs.kindgi.com/reference/errors.md)
