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.
List secrets for the authenticated user
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.
Fine-grained access tokens for "List secrets for the authenticated user"
This endpoint works with the following fine-grained token types:
The fine-grained token must have the following permission set:
- "Codespaces user secrets" user permissions (read)
Parameters for "List secrets for the authenticated user"
| Name, Type, Description |
|---|
accept string Setting to |
| Name, Type, Description |
|---|
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." Default: |
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." Default: |
HTTP response status codes for "List secrets for the authenticated user"
| Status code | Description |
|---|---|
200 | OK |
Code samples for "List secrets for the authenticated user"
If you access GitHub at GHE.com, replace api.github.com with your enterprise's dedicated subdomain at api.SUBDOMAIN.ghe.com.
Request example
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/user/codespaces/secretsResponse
Status: 200{
"total_count": 2,
"secrets": [
{
"name": "GH_TOKEN",
"created_at": "2019-08-10T14:59:22Z",
"updated_at": "2020-01-10T14:59:22Z",
"visibility": "all"
},
{
"name": "GIST_ID",
"created_at": "2020-01-10T10:59:22Z",
"updated_at": "2020-01-11T11:59:22Z",
"visibility": "all"
}
]
}Get public key for the authenticated user
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.
Fine-grained access tokens for "Get public key for the authenticated user"
This endpoint works with the following fine-grained token types:
The fine-grained token must have the following permission set:
- "Codespaces user secrets" user permissions (read)
HTTP response status codes for "Get public key for the authenticated user"
| Status code | Description |
|---|---|
200 | OK |
Code samples for "Get public key for the authenticated user"
If you access GitHub at GHE.com, replace api.github.com with your enterprise's dedicated subdomain at api.SUBDOMAIN.ghe.com.
Request example
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/user/codespaces/secrets/public-keyResponse
Status: 200{
"key_id": "012345678912345678",
"key": "2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234"
}Get a secret for the authenticated user
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.
Fine-grained access tokens for "Get a secret for the authenticated user"
This endpoint works with the following fine-grained token types:
The fine-grained token must have the following permission set:
- "Codespaces user secrets" user permissions (read)
Parameters for "Get a secret for the authenticated user"
| Name, Type, Description |
|---|
accept string Setting to |
| Name, Type, Description |
|---|
secret_name string RequiredThe name of the secret. |
HTTP response status codes for "Get a secret for the authenticated user"
| Status code | Description |
|---|---|
200 | OK |
Code samples for "Get a secret for the authenticated user"
If you access GitHub at GHE.com, replace api.github.com with your enterprise's dedicated subdomain at api.SUBDOMAIN.ghe.com.
Request example
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
-H "X-GitHub-Api-Version: 2026-03-10" \
https://api.github.com/user/codespaces/secrets/SECRET_NAMEResponse
Status: 200{
"name": "CODESPACE_GH_SECRET",
"created_at": "2019-08-10T14:59:22Z",
"updated_at": "2020-01-10T14:59:22Z",
"visibility": "selected",
"selected_repositories_url": "https://api.github.com/user/codespaces/secrets/CODESPACE_GH_SECRET/repositories"
}Create or update a secret for the authenticated user
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.
Fine-grained access tokens for "Create or update a secret for the authenticated user"
This endpoint works with the following fine-grained token types:
The fine-grained token must have the following permission set:
- "Codespaces user secrets" user permissions (write)
Parameters for "Create or update a secret for the authenticated user"
| Name, Type, Description |
|---|
accept string Setting to |
| Name, Type, Description |
|---|
secret_name string RequiredThe name of the secret. |
| Name, Type, Description |
|---|
encrypted_value string Value for your secret, encrypted with LibSodium using the public key retrieved from the Get the public key for the authenticated user endpoint. |
key_id string RequiredID of the key you used to encrypt the secret. |
selected_repository_ids array An array of repository ids that can access the user secret. You can manage the list of selected repositories using the List selected repositories for a user secret, Set selected repositories for a user secret, and Remove a selected repository from a user secret endpoints. |
HTTP response status codes for "Create or update a secret for the authenticated user"
| Status code | Description |
|---|---|
201 | Response after successfully creating a secret |
204 | Response after successfully updating a secret |
404 | Resource not found |
422 | Validation failed, or the endpoint has been spammed. |
Code samples for "Create or update a secret for the authenticated user"
If you access GitHub at GHE.com, replace api.github.com with your enterprise's dedicated subdomain at api.SUBDOMAIN.ghe.com.