{"meta":{"title":"适用于 Codespaces 存储库机密的 REST API 终结点","intro":"使用 REST API 管理用户有权在 codespace 中访问的存储库的机密。","product":"REST API","breadcrumbs":[{"href":"/zh/rest","title":"REST API"},{"href":"/zh/rest/codespaces","title":"Codespaces"},{"href":"/zh/rest/codespaces/repository-secrets","title":"存储库机密"}],"documentType":"article"},"body":"# 适用于 Codespaces 存储库机密的 REST API 终结点\n\n使用 REST API 管理用户有权在 codespace 中访问的存储库的机密。\n\n## 关于 Codespaces 存储库机密\n\n可以为用户有权访问的存储库创建、列出和删除机密（如云服务的访问令牌）。 这些机密在运行时可供 codespace 使用。 有关详细信息，请参阅“[管理 GitHub Codespaces 的账户专属的机密](/zh/codespaces/managing-your-codespaces/managing-your-account-specific-secrets-for-github-codespaces)”。\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 repository secrets\n\n```\nGET /repos/{owner}/{repo}/codespaces/secrets\n```\n\nLists all development environment secrets available in a repository without revealing their encrypted\nvalues.\nOAuth app tokens and personal access tokens (classic) need the repo 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* **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n* **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\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/repos/OWNER/REPO/codespaces/secrets\n```\n\n**Response schema (Status: 200):**\n\n* `total_count`: required, integer\n* `secrets`: required, array of `Codespaces Secret`:\n  * `name`: required, string\n  * `created_at`: required, string, format: date-time\n  * `updated_at`: required, string, format: date-time\n\n## Get a repository public key\n\n```\nGET /repos/{owner}/{repo}/codespaces/secrets/public-key\n```\n\nGets your public key, which you need to encrypt secrets. You need to\nencrypt a secret before you can create or update secrets.\nIf the repository is private, OAuth app tokens and personal access tokens (classic) need the repo 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* **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n* **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\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/repos/OWNER/REPO/codespaces/secrets/public-key\n```\n\n**Response schema (Status: 200):**\n\n* `key_id`: required, string\n* `key`: required, string\n* `id`: integer\n* `url`: string\n* `title`: string\n* `created_at`: string\n\n## Get a repository secret\n\n```\nGET /repos/{owner}/{repo}/codespaces/secrets/{secret_name}\n```\n\nGets a single repository development environment secret without revealing its encrypted value.\nOAuth app tokens and personal access tokens (classic) need the repo 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* **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n* **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n* **`secret_name`** (string) (required)\n  The name of the secret.\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/repos/OWNER/REPO/codespaces/secrets/SECRET_NAME\n```\n\n**Response schema (Status: 200):**\n\n* `name`: required, string\n* `created_at`: required, string, format: date-time\n* `updated_at`: required, string, format: date-time\n\n## Create or update a repository secret\n\n```\nPUT /repos/{owner}/{repo}/codespaces/secrets/{secret_name}\n```\n\nCreates or updates a repository development environment secret with an encrypted value. Encrypt your secret using\nLibSodium. For more information, see \"Encrypting secrets for the REST API.\"\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint. The associated user must be a repository admin.\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* **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n* **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n* **`secret_name`** (string) (required)\n  The name of the secret.\n\n#### Body parameters\n\n* **`encrypted_value`** (string)\n  Value for your secret, encrypted with LibSodium using the public key retrieved from the Get a repository public key endpoint.\n\n* **`key_id`** (string)\n  ID of the key you used to encrypt the secret.\n\n### HTTP response status codes\n\n* **201** - Response when creating a secret\n\n* **204** - Response when updating a secret\n\n### Code examples\n\n#### Example 1: Status Code 201\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PUT \\\n  https://api.github.com/repos/OWNER/REPO/codespaces/secrets/SECRET_NAME \\\n  -d '{\n  \"encrypted_value\": \"c2VjcmV0\",\n  \"key_id\": \"012345678912345678\"\n}'\n```\n\n**Response schema (Status: 201):**\n\n#### Example 2: Status Code 204\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PUT \\\n  https://api.github.com/repos/OWNER/REPO/codespaces/secrets/SECRET_NAME \\\n  -d '{\n  \"encrypted_value\": \"c2VjcmV0\",\n  \"key_id\": \"012345678912345678\"\n}'\n```\n\n**Response schema (Status: 204):**\n\n## Delete a repository secret\n\n```\nDELETE /repos/{owner}/{repo}/codespaces/secrets/{secret_name}\n```\n\nDeletes a development environment secret in a repository using the secret name.\nOAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint. The associated user must be a repository admin.\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* **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n* **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n* **`secret_name`** (string) (required)\n  The name of the secret.\n\n### HTTP response status codes\n\n* **204** - No Content\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  https://api.github.com/repos/OWNER/REPO/codespaces/secrets/SECRET_NAME\n```\n\n**Response schema (Status: 204):**"}