{"meta":{"title":"REST API endpoints for GPG keys","intro":"Use the REST API to manage GPG keys of authenticated users.","product":"REST API","breadcrumbs":[{"href":"/en/enterprise-cloud@latest/rest","title":"REST API"},{"href":"/en/enterprise-cloud@latest/rest/users","title":"Users"},{"href":"/en/enterprise-cloud@latest/rest/users/gpg-keys","title":"GPG keys"}],"documentType":"article"},"body":"# REST API endpoints for GPG keys\n\nUse the REST API to manage GPG keys of authenticated users.\n\n## About user GPG key administration\n\nThe 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.\n\nIf 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](/en/enterprise-cloud@latest/rest/authentication/authenticating-to-the-rest-api) 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.\n\n> \\[!NOTE]\n> 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.\n\n## List GPG keys for the authenticated user\n\n```\nGET /user/gpg_keys\n```\n\nLists the current user's GPG keys.\nOAuth app tokens and personal access tokens (classic) need the read:gpg\\_key scope to use this endpoint.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n* **`page`** (integer)\n  The page number of the results to fetch. For more information, see \"Using pagination in the REST API.\"\n  Default: `1`\n\n### HTTP response status codes\n\n* **200** - OK\n\n* **304** - Not modified\n\n* **401** - Requires authentication\n\n* **403** - Forbidden\n\n* **404** - Resource not found\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/user/gpg_keys\n```\n\n**Response schema (Status: 200):**\n\nArray of `GPG Key`:\n\n* `id`: required, integer, format: int64\n* `name`: string or null\n* `primary_key_id`: required, integer or null\n* `key_id`: required, string\n* `public_key`: required, string\n* `emails`: required, array of objects:\n  * `email`: string\n  * `verified`: boolean\n* `subkeys`: required, array of objects:\n  * `id`: integer, format: int64\n  * `primary_key_id`: integer\n  * `key_id`: string\n  * `public_key`: string\n  * `emails`: array of objects:\n    * `email`: string\n    * `verified`: boolean\n  * `subkeys`: array of object\n  * `can_sign`: boolean\n  * `can_encrypt_comms`: boolean\n  * `can_encrypt_storage`: boolean\n  * `can_certify`: boolean\n  * `created_at`: string\n  * `expires_at`: string or null\n  * `raw_key`: string or null\n  * `revoked`: boolean\n* `can_sign`: required, boolean\n* `can_encrypt_comms`: required, boolean\n* `can_encrypt_storage`: required, boolean\n* `can_certify`: required, boolean\n* `created_at`: required, string, format: date-time\n* `expires_at`: required, string or null, format: date-time\n* `revoked`: required, boolean\n* `raw_key`: required, string or null\n\n## Create a GPG key for the authenticated user\n\n```\nPOST /user/gpg_keys\n```\n\nAdds a GPG key to the authenticated user's GitHub account.\nOAuth app tokens and personal access tokens (classic) need the write:gpg\\_key scope to use this endpoint.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Body parameters\n\n* **`name`** (string)\n  A descriptive name for the new key.\n\n* **`armored_public_key`** (string) (required)\n  A GPG key in ASCII-armored format.\n\n### HTTP response status codes\n\n* **201** - Created\n\n* **304** - Not modified\n\n* **401** - Requires authentication\n\n* **403** - Forbidden\n\n* **404** - Resource not found\n\n* **422** - Validation failed, or the endpoint has been spammed.\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  https://api.github.com/user/gpg_keys \\\n  -d '{\n  \"name\": \"Octocat's GPG Key\",\n  \"armored_public_key\": \"-----BEGIN PGP PUBLIC KEY BLOCK-----\\nVersion: GnuPG v1\\n\\nmQINBFnZ2ZIBEADQ2Z7Z7\\n-----END PGP PUBLIC KEY BLOCK-----\"\n}'\n```\n\n**Response schema (Status: 201):**\n\n* `id`: required, integer, format: int64\n* `name`: string or null\n* `primary_key_id`: required, integer or null\n* `key_id`: required, string\n* `public_key`: required, string\n* `emails`: required, array of objects:\n  * `email`: string\n  * `verified`: boolean\n* `subkeys`: required, array of objects:\n  * `id`: integer, format: int64\n  * `primary_key_id`: integer\n  * `key_id`: string\n  * `public_key`: string\n  * `emails`: array of objects:\n    * `email`: string\n    * `verified`: boolean\n  * `subkeys`: array of object\n  * `can_sign`: boolean\n  * `can_encrypt_comms`: boolean\n  * `can_encrypt_storage`: boolean\n  * `can_certify`: boolean\n  * `created_at`: string\n  * `expires_at`: string or null\n  * `raw_key`: string or null\n  * `revoked`: boolean\n* `can_sign`: required, boolean\n* `can_encrypt_comms`: required, boolean\n* `can_encrypt_storage`: required, boolean\n* `can_certify`: required, boolean\n* `created_at`: required, string, format: date-time\n* `expires_at`: required, string or null, format: date-time\n* `revoked`: required, boolean\n* `raw_key`: required, string or null\n\n## Get a GPG key for the authenticated user\n\n```\nGET /user/gpg_keys/{gpg_key_id}\n```\n\nView extended details for a single GPG key.\nOAuth app tokens and personal access tokens (classic) need the read:gpg\\_key scope to use this endpoint.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`gpg_key_id`** (integer) (required)\n  The unique identifier of the GPG key.\n\n### HTTP response status codes\n\n* **200** - OK\n\n* **304** - Not modified\n\n* **401** - Requires authentication\n\n* **403** - Forbidden\n\n* **404** - Resource not found\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/user/gpg_keys/GPG_KEY_ID\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a GPG key for the authenticated user](#create-a-gpg-key-for-the-authenticated-user).\n\n## Delete a GPG key for the authenticated user\n\n```\nDELETE /user/gpg_keys/{gpg_key_id}\n```\n\nRemoves a GPG key from the authenticated user's GitHub account.\nOAuth app tokens and personal access tokens (classic) need the admin:gpg\\_key scope to use this endpoint.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`gpg_key_id`** (integer) (required)\n  The unique identifier of the GPG key.\n\n### HTTP response status codes\n\n* **204** - No Content\n\n* **304** - Not modified\n\n* **401** - Requires authentication\n\n* **403** - Forbidden\n\n* **404** - Resource not found\n\n* **422** - Validation failed, or the endpoint has been spammed.\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  https://api.github.com/user/gpg_keys/GPG_KEY_ID\n```\n\n**Response schema (Status: 204):**\n\n## List GPG keys for a user\n\n```\nGET /users/{username}/gpg_keys\n```\n\nLists the GPG keys for a user. This information is accessible by anyone.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n* **`username`** (string) (required)\n  The handle for the GitHub user account.\n\n* **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n* **`page`** (integer)\n  The page number of the results to fetch. For more information, see \"Using pagination in the REST API.\"\n  Default: `1`\n\n### HTTP response status codes\n\n* **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/users/USERNAME/gpg_keys\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [List GPG keys for the authenticated user](#list-gpg-keys-for-the-authenticated-user)."}