Use the REST API manage secrets that the user has access to in a codespace.
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.
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.
accept (string)application/vnd.github+json is recommended.per_page (integer)
The number of results per page (max 100). For more information, see "Using pagination in the REST API."
Default: 30
page (integer)
The page number of the results to fetch. For more information, see "Using pagination in the REST API."
Default: 1
Request:
curl -L \
-X GET \
https://api.github.com/user/codespaces/secrets
Response schema (Status: 200):
total_count: required, integersecrets: required, array of Codespaces Secret:
name: required, stringcreated_at: required, string, format: date-timeupdated_at: required, string, format: date-timevisibility: required, string, enum: all, private, selectedselected_repositories_url: required, string, format: uriGET /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.
Request:
curl -L \
-X GET \
https://api.github.com/user/codespaces/secrets/public-key
Response schema (Status: 200):
key_id: required, stringkey: required, stringGET /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.
accept (string)application/vnd.github+json is recommended.secret_name (string) (required)Request:
curl -L \
-X GET \
https://api.github.com/user/codespaces/secrets/SECRET_NAME
Response schema (Status: 200):
name: required, stringcreated_at: required, string, format: date-timeupdated_at: required, string, format: date-timevisibility: required, string, enum: all, private, selectedselected_repositories_url: required, string, format: uriPUT /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.
accept (string)application/vnd.github+json is recommended.secret_name (string) (required)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) (required)
ID 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.
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.
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):
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 /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.
accept (string)application/vnd.github+json is recommended.secret_name (string) (required)Request:
curl -L \
-X DELETE \
https://api.github.com/user/codespaces/secrets/SECRET_NAME
Response schema (Status: 204):
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.
accept (string)application/vnd.github+json is recommended.secret_name (string) (required)200 - OK
401 - Requires authentication
403 - Forbidden
404 - Resource not found
500 - Internal Error
Request:
curl -L \
-X GET \
https://api.github.com/user/codespaces/secrets/SECRET_NAME/repositories
Response schema (Status: 200):
total_count: required, integerrepositories: required, array of Minimal Repository:
id: required, integer, format: int64node_id: required, stringname: required, stringfull_name: required, stringowner: required, Simple User:
name: string or nullemail: string or nulllogin: required, stringid: required, integer, format: int64node_id: required, stringavatar_url: required, string, format: urigravatar_id: required, string or nullurl: required, string, format: urihtml_url: required, string, format: urifollowers_url: required, string, format: urifollowing_url: required, stringgists_url: required, stringstarred_url: required, stringsubscriptions_url: required, string, format: uriorganizations_url: required, string, format: urirepos_url: required, string, format: urievents_url: required, stringreceived_events_url: required, string, format: uritype: required, stringsite_admin: required, booleanstarred_at: stringuser_view_type: stringprivate: required, booleanhtml_url: required, string, format: uridescription: required, string or nullfork: required, booleanurl: required, string, format: uriarchive_url: required, stringassignees_url: required, stringblobs_url: required, stringbranches_url: required, stringcollaborators_url: required, stringcomments_url: required, stringcommits_url: required, stringcompare_url: required, stringcontents_url: required, stringcontributors_url: required, string, format: urideployments_url: required, string, format: uridownloads_url: required, string, format: urievents_url: required, string, format: uriforks_url: required, string, format: urigit_commits_url: required, stringgit_refs_url: required, stringgit_tags_url: required, stringgit_url: stringissue_comment_url: required, stringissue_events_url: required, stringissues_url: required, stringkeys_url: required, stringlabels_url: required, stringlanguages_url: required, string, format: urimerges_url: required, string, format: urimilestones_url: required, stringnotifications_url: required, stringpulls_url: required, stringreleases_url: required, stringssh_url: stringstargazers_url: required, string, format: uristatuses_url: required, stringsubscribers_url: required, string, format: urisubscription_url: required, string, format: uritags_url: required, string, format: uriteams_url: required, string, format: uritrees_url: required, stringclone_url: stringmirror_url: string or nullhooks_url: required, string, format: urisvn_url: stringhomepage: string or nulllanguage: string or nullforks_count: integerstargazers_count: integerwatchers_count: integersize: integerdefault_branch: stringopen_issues_count: integeris_template: booleantopics: array of stringhas_issues: booleanhas_projects: booleanhas_wiki: booleanhas_pages: booleanhas_discussions: booleanhas_pull_requests: booleanpull_request_creation_policy: string, enum: all, collaborators_onlyarchived: booleandisabled: booleanvisibility: stringpushed_at: string or null, format: date-timecreated_at: string or null, format: date-timeupdated_at: string or null, format: date-timepermissions: object:
admin: booleanmaintain: booleanpush: booleantriage: booleanpull: booleanrole_name: stringtemp_clone_token: stringdelete_branch_on_merge: booleansubscribers_count: integernetwork_count: integercode_of_conduct: Code Of Conduct:
key: required, stringname: required, stringurl: required, string, format: uribody: stringhtml_url: required, string or null, format: urilicense: object or null:
key: stringname: stringspdx_id: stringurl: string or nullnode_id: stringforks: integeropen_issues: integerwatchers: integerallow_forking: booleanweb_commit_signoff_required: booleansecurity_and_analysis: object or null:
advanced_security: object:
status: string, enum: enabled, disabledcode_security: object:
status: string, enum: enabled, disableddependabot_security_updates: object:
status: string, enum: enabled, disabledsecret_scanning: object:
status: string, enum: enabled, disabledsecret_scanning_push_protection: object:
status: string, enum: enabled, disabledsecret_scanning_non_provider_patterns: object:
status: string, enum: enabled, disabledsecret_scanning_ai_detection: object:
status: string, enum: enabled, disabledsecret_scanning_delegated_alert_dismissal: object:
status: string, enum: enabled, disabledsecret_scanning_delegated_bypass: object:
status: string, enum: enabled, disabledsecret_scanning_delegated_bypass_options: object:
reviewers: array of objects:
reviewer_id: required, integerreviewer_type: required, string, enum: TEAM, ROLEmode: string, enum: ALWAYS, EXEMPT, default: "ALWAYS"custom_properties: object, additional properties allowedPUT /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.
accept (string)application/vnd.github+json is recommended.secret_name (string) (required)selected_repository_ids (array of integers) (required)204 - No Content when repositories were added to the selected list
401 - Requires authentication
403 - Forbidden
404 - Resource not found
500 - Internal Error
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):
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.
accept (string)application/vnd.github+json is recommended.secret_name (string) (required)
The name of the secret.
repository_id (integer) (required)
204 - No Content when repository was added to the selected list
401 - Requires authentication
403 - Forbidden
404 - Resource not found
500 - Internal Error
Request:
curl -L \
-X PUT \
https://api.github.com/user/codespaces/secrets/SECRET_NAME/repositories/REPOSITORY_ID
Response schema (Status: 204):
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.
accept (string)application/vnd.github+json is recommended.secret_name (string) (required)
The name of the secret.
repository_id (integer) (required)
204 - No Content when repository was removed from the selected list
401 - Requires authentication
403 - Forbidden
404 - Resource not found
500 - Internal Error
Request:
curl -L \
-X DELETE \
https://api.github.com/user/codespaces/secrets/SECRET_NAME/repositories/REPOSITORY_ID
Response schema (Status: 204):