REST API endpoints for Codespaces user secrets

Use the REST API manage secrets that the user has access to in a codespace.

About Codespaces user secrets

You can create, list, and delete secrets (such as access tokens for cloud services) as well as assign secrets to repositories that the user has access to. These secrets are made available to the codespace at runtime. For more information, see Managing your account-specific secrets for GitHub Codespaces.

Note

Most endpoints use Authorization: Bearer <YOUR-TOKEN> and Accept: application/vnd.github+json headers, plus X-GitHub-Api-Version: 2026-03-10. Curl examples below omit these standard headers for brevity.

List secrets for the authenticated user

GET /user/codespaces/secrets

Lists all development environment secrets available for a user's codespaces without revealing their
encrypted values.
The authenticated user must have Codespaces access to use this endpoint.
OAuth app tokens and personal access tokens (classic) need the codespace or codespace:secrets scope to use this endpoint.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/user/codespaces/secrets

Response schema (Status: 200):

Get public key for the authenticated user

GET /user/codespaces/secrets/public-key

Gets your public key, which you need to encrypt secrets. You need to encrypt a secret before you can create or update secrets.
The authenticated user must have Codespaces access to use this endpoint.
OAuth app tokens and personal access tokens (classic) need the codespace or codespace:secrets scope to use this endpoint.

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/user/codespaces/secrets/public-key

Response schema (Status: 200):

Get a secret for the authenticated user

GET /user/codespaces/secrets/{secret_name}

Gets a development environment secret available to a user's codespaces without revealing its encrypted value.
The authenticated user must have Codespaces access to use this endpoint.
OAuth app tokens and personal access tokens (classic) need the codespace or codespace:secrets scope to use this endpoint.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/user/codespaces/secrets/SECRET_NAME

Response schema (Status: 200):

Create or update a secret for the authenticated user

PUT /user/codespaces/secrets/{secret_name}

Creates or updates a development environment secret for a user's codespace with an encrypted value. Encrypt your secret using
LibSodium. For more information, see "Encrypting secrets for the REST API."
The authenticated user must have Codespaces access to use this endpoint.
OAuth app tokens and personal access tokens (classic) need the codespace or codespace:secrets scope to use this endpoint.

Parameters

Headers

Path and query parameters

Body parameters

HTTP response status codes

Code examples

Example 1: Status Code 201

Request:

curl -L \
  -X PUT \
  https://api.github.com/user/codespaces/secrets/SECRET_NAME \
  -d '{
  "encrypted_value": "c2VjcmV0",
  "key_id": "012345678912345678",
  "selected_repository_ids": [
    "1234567",
    "2345678"
  ]
}'

Response schema (Status: 201):

Example 2: Status Code 204

Request:

curl -L \
  -X PUT \
  https://api.github.com/user/codespaces/secrets/SECRET_NAME \
  -d '{
  "encrypted_value": "c2VjcmV0",
  "key_id": "012345678912345678",
  "selected_repository_ids": [
    "1234567",
    "2345678"
  ]
}'

Response schema (Status: 204):

Delete a secret for the authenticated user

DELETE /user/codespaces/secrets/{secret_name}

Deletes a development environment secret from a user's codespaces using the secret name. Deleting the secret will remove access from all codespaces that were allowed to access the secret.
The authenticated user must have Codespaces access to use this endpoint.
OAuth app tokens and personal access tokens (classic) need the codespace or codespace:secrets scope to use this endpoint.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X DELETE \
  https://api.github.com/user/codespaces/secrets/SECRET_NAME

Response schema (Status: 204):

List selected repositories for a user secret

GET /user/codespaces/secrets/{secret_name}/repositories

List the repositories that have been granted the ability to use a user's development environment secret.
The authenticated user must have Codespaces access to use this endpoint.
OAuth app tokens and personal access tokens (classic) need the codespace or codespace:secrets scope to use this endpoint.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X GET \
  https://api.github.com/user/codespaces/secrets/SECRET_NAME/repositories

Response schema (Status: 200):

Set selected repositories for a user secret

PUT /user/codespaces/secrets/{secret_name}/repositories

Select the repositories that will use a user's development environment secret.
The authenticated user must have Codespaces access to use this endpoint.
OAuth app tokens and personal access tokens (classic) need the codespace or codespace:secrets scope to use this endpoint.

Parameters

Headers

Path and query parameters

Body parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X PUT \
  https://api.github.com/user/codespaces/secrets/SECRET_NAME/repositories \
  -d '{
  "selected_repository_ids": [
    "1296269",
    "1296280"
  ]
}'

Response schema (Status: 204):

Add a selected repository to a user secret

PUT /user/codespaces/secrets/{secret_name}/repositories/{repository_id}

Adds a repository to the selected repositories for a user's development environment secret.
The authenticated user must have Codespaces access to use this endpoint.
OAuth app tokens and personal access tokens (classic) need the codespace or codespace:secrets scope to use this endpoint.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X PUT \
  https://api.github.com/user/codespaces/secrets/SECRET_NAME/repositories/REPOSITORY_ID

Response schema (Status: 204):

Remove a selected repository from a user secret

DELETE /user/codespaces/secrets/{secret_name}/repositories/{repository_id}

Removes a repository from the selected repositories for a user's development environment secret.
The authenticated user must have Codespaces access to use this endpoint.
OAuth app tokens and personal access tokens (classic) need the codespace or codespace:secrets scope to use this endpoint.

Parameters

Headers

Path and query parameters

HTTP response status codes

Code examples

Example

Request:

curl -L \
  -X DELETE \
  https://api.github.com/user/codespaces/secrets/SECRET_NAME/repositories/REPOSITORY_ID

Response schema (Status: 204):