Sample - GitHub REST API
POST/repos/{owner}/{repo}/pulls/{pull_number}/codespaces

Create a codespace from a pull request

Creates a codespace owned by the authenticated user for the specified pull request.

OAuth app tokens and personal access tokens (classic) need the codespace scope to use this endpoint.

  • RetriesRetries up to 2×, 500ms backoff, 30s timeout.

3 parameters · 10 body fields
ownerstringrequired
The account owner of the repository. The name is not case sensitive.
repostringrequired
The name of the repository without the `.git` extension. The name is not case sensitive.
pull_numberintegerrequired
The number that identifies the pull request.
locationstringoptional
The requested location for a new codespace. Best efforts are made to respect this upon creation. Assigned by IP if not provided.
geostringoptional
The geographic area for this codespace. If not specified, the value is assigned by IP. This property replaces `location`, which is closing down.
Allowed:EuropeWestSoutheastAsiaUsEastUsWest
client_ipstringoptional
IP for location auto-detection when proxying a request
machinestringoptional
Machine type to use for this codespace
devcontainer_pathstringoptional
Path to devcontainer.json config to use for this codespace
multi_repo_permissions_opt_outbooleanoptional
Whether to authorize requested permissions from devcontainer.json
working_directorystringoptional
Working directory for this codespace
idle_timeout_minutesintegeroptional
Time in minutes before codespace stops from inactivity
display_namestringoptional
Display name for this codespace
retention_period_minutesintegeroptional
Duration in minutes after codespace has gone idle in which it will be deleted. Must be integer minutes between 0 and 43200 (30 days).

6 status codes
201Response when the codespace was successfully created
idintegerrequired
namestringrequired
Automatically generated name of this codespace.
display_namestringoptional
Display name for this codespace.
environment_idstringrequired
UUID identifying this codespace's environment.
ownerobjectrequired
A GitHub user.
billable_ownerobjectrequired
A GitHub user.
repositoryobjectrequired
Minimal Repository
machineobjectrequired
A description of the machine powering a codespace.
devcontainer_pathstringoptional
Path to devcontainer.json from repo root used to create Codespace.
prebuildbooleanrequired
Whether the codespace was created from a prebuild.
created_atstringrequired
updated_atstringrequired
last_used_atstringrequired
Last known time this codespace was started.
statestringrequired
State of this codespace.
Allowed:UnknownCreatedQueuedProvisioningAvailableAwaitingUnavailableDeletedMovedShutdownArchivedStarting
urlstringrequired
API URL for this codespace.
git_statusobjectrequired
Details about the codespace's git repository.
locationstringrequired
The initally assigned location of a new codespace.
Allowed:EastUsSouthEastAsiaWestEuropeWestUs2
idle_timeout_minutesintegerrequired
The number of minutes of inactivity after which this codespace will be automatically stopped.
web_urlstringrequired
URL to access this codespace on the web.
machines_urlstringrequired
API URL to access available alternate machine types for this codespace.
start_urlstringrequired
API URL to start this codespace.
stop_urlstringrequired
API URL to stop this codespace.
publish_urlstringoptional
API URL to publish this codespace to a new repository.
pulls_urlstringrequired
API URL for the Pull Request associated with this codespace, if any.
recent_foldersarray<string>required
runtime_constraintsobjectoptional
pending_operationbooleanoptional
Whether or not a codespace has a pending async operation. This would mean that the codespace is temporarily unavailable. The only thing that you can do with a codespace in this state is delete it.
pending_operation_disabled_reasonstringoptional
Text to show user when codespace is disabled by a pending operation
idle_timeout_noticestringoptional
Text to show user when codespace idle timeout minutes has been overriden by an organization policy
retention_period_minutesintegeroptional
Duration in minutes after codespace has gone idle in which it will be deleted. Must be integer minutes between 0 and 43200 (30 days).
retention_expires_atstringoptional
When a codespace will be auto-deleted based on the "retention_period_minutes" and "last_used_at"
last_known_stop_noticestringoptional
The text to display to a user when a codespace has been stopped for a potentially actionable reason.
202Response when the codespace creation partially failed but is being retried in the background
idintegerrequired
namestringrequired
Automatically generated name of this codespace.
display_namestringoptional
Display name for this codespace.
environment_idstringrequired
UUID identifying this codespace's environment.
ownerobjectrequired
A GitHub user.
billable_ownerobjectrequired
A GitHub user.
repositoryobjectrequired
Minimal Repository
machineobjectrequired
A description of the machine powering a codespace.
devcontainer_pathstringoptional
Path to devcontainer.json from repo root used to create Codespace.
prebuildbooleanrequired
Whether the codespace was created from a prebuild.
created_atstringrequired
updated_atstringrequired
last_used_atstringrequired
Last known time this codespace was started.
statestringrequired
State of this codespace.
Allowed:UnknownCreatedQueuedProvisioningAvailableAwaitingUnavailableDeletedMovedShutdownArchivedStarting
urlstringrequired
API URL for this codespace.
git_statusobjectrequired
Details about the codespace's git repository.
locationstringrequired
The initally assigned location of a new codespace.
Allowed:EastUsSouthEastAsiaWestEuropeWestUs2
idle_timeout_minutesintegerrequired
The number of minutes of inactivity after which this codespace will be automatically stopped.
web_urlstringrequired
URL to access this codespace on the web.
machines_urlstringrequired
API URL to access available alternate machine types for this codespace.
start_urlstringrequired
API URL to start this codespace.
stop_urlstringrequired
API URL to stop this codespace.
publish_urlstringoptional
API URL to publish this codespace to a new repository.
pulls_urlstringrequired
API URL for the Pull Request associated with this codespace, if any.
recent_foldersarray<string>required
runtime_constraintsobjectoptional
pending_operationbooleanoptional
Whether or not a codespace has a pending async operation. This would mean that the codespace is temporarily unavailable. The only thing that you can do with a codespace in this state is delete it.
pending_operation_disabled_reasonstringoptional
Text to show user when codespace is disabled by a pending operation
idle_timeout_noticestringoptional
Text to show user when codespace idle timeout minutes has been overriden by an organization policy
retention_period_minutesintegeroptional
Duration in minutes after codespace has gone idle in which it will be deleted. Must be integer minutes between 0 and 43200 (30 days).
retention_expires_atstringoptional
When a codespace will be auto-deleted based on the "retention_period_minutes" and "last_used_at"
last_known_stop_noticestringoptional
The text to display to a user when a codespace has been stopped for a potentially actionable reason.
401Requires authentication
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
403Forbidden
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
404Resource not found
messagestringoptional
documentation_urlstringoptional
urlstringoptional
statusstringoptional
503Service unavailable
codestringoptional
messagestringoptional
documentation_urlstringoptional

Error handling

A 401 is returned: Requires authentication. A 403 is returned: Forbidden. A 404 is returned: Resource not found. A 503 is returned: Service unavailable.