Use the REST API to manage GPG keys of authenticated users.
The data returned in the public_key response field is not a GPG formatted key. When a user uploads a GPG key, it is parsed and the cryptographic public key is extracted and stored. This cryptographic key is what the endpoints in this category will return. This key is not suitable for direct use in programs such as GPG.
If a request URL does not include a {username} parameter then the response will be for the signed-in user (and you must pass authentication information with your request). Additional private information, such as whether a user has two-factor authentication enabled, is included when authenticated through OAuth with the user scope.
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/gpg_keys
Lists the current user's GPG keys.
OAuth app tokens and personal access tokens (classic) need the read:gpg_key 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
200 - OK
304 - Not modified
401 - Requires authentication
403 - Forbidden
404 - Resource not found
Request:
curl -L \
-X GET \
https://api.github.com/user/gpg_keys
Response schema (Status: 200):
Array of GPG Key:
id: required, integer, format: int64name: string or nullprimary_key_id: required, integer or nullkey_id: required, stringpublic_key: required, stringemails: required, array of objects:
email: stringverified: booleansubkeys: required, array of objects:
id: integer, format: int64primary_key_id: integerkey_id: stringpublic_key: stringemails: array of objects:
email: stringverified: booleansubkeys: array of objectcan_sign: booleancan_encrypt_comms: booleancan_encrypt_storage: booleancan_certify: booleancreated_at: stringexpires_at: string or nullraw_key: string or nullrevoked: booleancan_sign: required, booleancan_encrypt_comms: required, booleancan_encrypt_storage: required, booleancan_certify: required, booleancreated_at: required, string, format: date-timeexpires_at: required, string or null, format: date-timerevoked: required, booleanraw_key: required, string or nullPOST /user/gpg_keys
Adds a GPG key to the authenticated user's GitHub account.
OAuth app tokens and personal access tokens (classic) need the write:gpg_key scope to use this endpoint.
accept (string)application/vnd.github+json is recommended.name (string)
A descriptive name for the new key.
armored_public_key (string) (required)
A GPG key in ASCII-armored format.
201 - Created
304 - Not modified
401 - Requires authentication
403 - Forbidden
404 - Resource not found
422 - Validation failed, or the endpoint has been spammed.
Request:
curl -L \
-X POST \
https://api.github.com/user/gpg_keys \
-d '{
"name": "Octocat'\''s GPG Key",
"armored_public_key": "-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: GnuPG v1\n\nmQINBFnZ2ZIBEADQ2Z7Z7\n-----END PGP PUBLIC KEY BLOCK-----"
}'
Response schema (Status: 201):
id: required, integer, format: int64name: string or nullprimary_key_id: required, integer or nullkey_id: required, stringpublic_key: required, stringemails: required, array of objects:
email: stringverified: booleansubkeys: required, array of objects:
id: integer, format: int64primary_key_id: integerkey_id: stringpublic_key: stringemails: array of objects:
email: stringverified: booleansubkeys: array of objectcan_sign: booleancan_encrypt_comms: booleancan_encrypt_storage: booleancan_certify: booleancreated_at: stringexpires_at: string or nullraw_key: string or nullrevoked: booleancan_sign: required, booleancan_encrypt_comms: required, booleancan_encrypt_storage: required, booleancan_certify: required, booleancreated_at: required, string, format: date-timeexpires_at: required, string or null, format: date-timerevoked: required, booleanraw_key: required, string or nullGET /user/gpg_keys/{gpg_key_id}
View extended details for a single GPG key.
OAuth app tokens and personal access tokens (classic) need the read:gpg_key scope to use this endpoint.
accept (string)application/vnd.github+json is recommended.gpg_key_id (integer) (required)200 - OK
304 - Not modified
401 - Requires authentication
403 - Forbidden
404 - Resource not found
Request:
curl -L \
-X GET \
https://api.github.com/user/gpg_keys/GPG_KEY_ID
Response schema (Status: 200):
Same response schema as Create a GPG key for the authenticated user.
DELETE /user/gpg_keys/{gpg_key_id}
Removes a GPG key from the authenticated user's GitHub account.
OAuth app tokens and personal access tokens (classic) need the admin:gpg_key scope to use this endpoint.
accept (string)application/vnd.github+json is recommended.gpg_key_id (integer) (required)204 - No Content
304 - Not modified
401 - Requires authentication
403 - Forbidden
404 - Resource not found
422 - Validation failed, or the endpoint has been spammed.
Request:
curl -L \
-X DELETE \
https://api.github.com/user/gpg_keys/GPG_KEY_ID
Response schema (Status: 204):
GET /users/{username}/gpg_keys
Lists the GPG keys for a user. This information is accessible by anyone.
accept (string)application/vnd.github+json is recommended.username (string) (required)
The handle for the GitHub user account.
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/users/USERNAME/gpg_keys
Response schema (Status: 200):
Same response schema as List GPG keys for the authenticated user.