{"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/machines","title":"机器"}],"documentType":"article"},"body":"# Codespaces 计算机的 REST API 终结点\n\n使用 REST API 管理 codespace 可用的机器类型。\n\n## 关于 Codespaces 计算机\n\n可以确定哪些机器类型可用于创建开发环境，无论是在特定的存储库上还是作为经过身份验证的用户。 有关详细信息，请参阅“[更改代码空间的计算机类型](/zh/codespaces/customizing-your-codespace/changing-the-machine-type-for-your-codespace#about-machine-types)”。\n\n您还可以在更改现有 codespace 的机器时，通过更新其 `machine` 属性来使用此信息。 计算机更新将在下次重新启动 codespace 时进行。 有关详细信息，请参阅“[更改代码空间的计算机类型](/zh/codespaces/customizing-your-codespace/changing-the-machine-type-for-your-codespace)”。\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 available machine types for a repository\n\n```\nGET /repos/{owner}/{repo}/codespaces/machines\n```\n\nList the machine types available for a given repository based on its configuration.\nOAuth app tokens and personal access tokens (classic) need the codespace 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* **`location`** (string)\n  The location to check for available machines. Assigned by IP if not provided.\n\n* **`client_ip`** (string)\n  IP for location auto-detection when proxying a request\n\n* **`ref`** (string)\n  The branch or commit to check for prebuild availability and devcontainer restrictions.\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* **500** - Internal Error\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/machines\n```\n\n**Response schema (Status: 200):**\n\n* `total_count`: required, integer\n* `machines`: required, array of `Codespace machine`:\n  * `name`: required, string\n  * `display_name`: required, string\n  * `operating_system`: required, string\n  * `storage_in_bytes`: required, integer\n  * `memory_in_bytes`: required, integer\n  * `cpus`: required, integer\n  * `prebuild_availability`: required, string or null, enum: `none`, `ready`, `in_progress`, `null`\n\n## List machine types for a codespace\n\n```\nGET /user/codespaces/{codespace_name}/machines\n```\n\nList the machine types a codespace can transition to use.\nOAuth app tokens and personal access tokens (classic) need the codespace 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* **`codespace_name`** (string) (required)\n  The name of the codespace.\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* **500** - Internal Error\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/user/codespaces/CODESPACE_NAME/machines\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [List available machine types for a repository](#list-available-machine-types-for-a-repository)."}