---
title: "Create or update a repository secret"
method: PUT
path: "/repos/{owner}/{repo}/codespaces/secrets/{secret_name}"
tags: ["codespaces"]
---

# Create or update a repository secret

`PUT /repos/{owner}/{repo}/codespaces/secrets/{secret_name}`

Creates or updates a repository development environment secret with an encrypted value. Encrypt your secret using
[LibSodium](https://libsodium.gitbook.io/doc/bindings_for_other_languages). For more information, see "[Encrypting secrets for the REST API](https://docs.github.com/rest/guides/encrypting-secrets-for-the-rest-api)."

OAuth app tokens and personal access tokens (classic) need the `repo` scope to use this endpoint. The associated user must be a repository admin.

## Path parameters

- `owner` string, required
- `repo` string, required
- `secret_name` string, required

## Request body

- object
  - `encrypted_value` string — Value for your secret, encrypted with [LibSodium](https://libsodium.gitbook.io/doc/bindings_for_other_languages) using the public key retrieved from the [Get a repository public key](https://docs.github.com/rest/codespaces/repository-secrets#get-a-repository-public-key) endpoint.
  - `key_id` string — ID of the key you used to encrypt the secret.

## Response `201`

Response when creating a secret

- EmptyObject — An object without any properties.

## Other responses

- `204` — Response when updating a secret

---

[API](https://skmtc.net/github/apis/rest-api.md) · [All operations](https://skmtc.net/github/apis/rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/github/rest-api/versions/80850db290cd/schema)
