PUT
PUT /user/codespaces/secrets/{secret_name} — GitHub API
GitHub token (required); https://api.github.com
GitHub APICreate or update a secret for the authenticated user
- Base URL
- https://api.github.com
- Auth
- Authorization: Bearer <GITHUB_API_KEY>
- Last verified
- 2026-10-20 · upstream hash matched
Actions Try in browser→
Agents: curl -H "Accept: text/markdown" this URL
→ 262 tokens · Vary: Accept
→ 262 tokens · Vary: Accept
Critical gotchas
GitHub recommends an Accept: application/vnd.github+json header and an explicit X-GitHub-Api-Version header.
Fine-grained tokens only authorize repositories and permissions selected when the token is created.
cURL
curl -X PUT 'https://api.github.com/user/codespaces/secrets/example-secret-name' \ -H "Authorization: Bearer $GITHUB_TOKEN" \ -H 'Accept: application/vnd.github+json' \ -H 'X-GitHub-Api-Version: 2026-03-10' \ -H 'Content-Type: application/json' \ -d '{ "key_id": "key-id"}'
Parameters
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| secret_name | path | string | Yes | The name of the secret. |
| encrypted_value | body | string | No | Value for your secret, encrypted with [LibSodium](https://libsodium.gitbook.io/doc/bindings_for_other_languages) using the public key retrieved from the [Get the public key for the authenticated user](https://docs.github.com/rest/codespaces/secrets#get-public-key-for-the-authenticated-user) endpoint. |
| key_id | body | string | Yes | ID of the key you used to encrypt the secret. |
| selected_repository_ids | body | integer[] | No | 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](https://docs.github.com/rest/codespaces/secrets#list-selected-repositories-for-a-user-secret), [Set selected repositories for a user secret](https://docs.github.com/rest/codespaces/secrets#set-selected-repositories-for-a-user-secret), and [Remove a selected repository from a user secret](https://docs.github.com/rest/codespaces/secrets#remove-a-selected-repository-from-a-user-secret) endpoints. |
Response 200 OK
{} Get a free GitHub API key → sponsored Affiliate link - we may earn a commission, at no extra cost to you.