# Create a pull request

Create a pull request

`POST /api/threads/{id}/pr`

Required permission: `thread:update`.

## Parameters

| Name | In | Type | Required | Description |

| --- | --- | --- | --- | --- |

| `id` | path | `string` | Yes | — |

| `Idempotency-Key` | header | `string` | No | Required for writes authenticated by a service credential and for service-account lifecycle writes. Other session writes may opt in. Reuse the key and payload for retries. Settled keys remain reserved for at least seven days; a transient 4xx releases its key. Changed payloads return 409. Match any legacy clientOperationId/clientMessageId in the body. |

## Request body

| Field | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| `title` | `string \| null` | No | — | — |
| `title.Option 1` | `string` | No | min length 1 | — |
| `title.Option 2` | `null` | No | — | — |
| `body` | `string \| null` | No | — | — |
| `draft` | `boolean` | No | — | — |
| `clientOperationId` | `string` | No | min length 1, max length 64 | — |

```json
{
  "title": "Factory change",
  "draft": true
}
```

## Example request

```bash
curl --request POST \
  --url https://api.hoplite.sh/api/threads/id/pr \
  --header "X-Api-Key: $HOPLITE_API_KEY" \
  --header "Idempotency-Key: $HOPLITE_OPERATION_ID" \
  --header 'Content-Type: application/json' \
  --data '{
  "title": "Factory change",
  "draft": true
}'
```

## 201 response

Successful response

Content type: `application/json`. Response type: `object`.

| Field | Type | Required | Constraints | Description |
| --- | --- | --- | --- | --- |
| `ok` | `boolean` | Yes | constant true | — |
| `pullRequest` | `object` | Yes | — | — |
| `pullRequest.id` | `string` | No | — | — |
| `pullRequest.threadId` | `string` | No | — | — |
| `pullRequest.number` | `number` | Yes | — | — |
| `pullRequest.url` | `string` | Yes | — | — |
| `pullRequest.repoFullName` | `string` | Yes | — | — |
| `pullRequest.state` | `string` | Yes | — | — |
| `pullRequest.headRef` | `string` | No | — | — |
| `pullRequest.headSha` | `string` | No | — | — |
| `pullRequest.baseRef` | `string` | No | — | — |
| `pullRequest.draft` | `boolean` | No | — | — |
| `pullRequest.version` | `integer` | No | min 0, max 9007199254740991 | — |
| `pullRequest.githubSummary` | `object \| null` | No | — | — |
| `pullRequest.githubSummary.Option 1` | `object` | No | — | — |
| `pullRequest.githubSummary.Option 1.state` | `string` | Yes | — | — |
| `pullRequest.githubSummary.Option 1.draft` | `boolean` | No | — | — |
| `pullRequest.githubSummary.Option 1.mergeable` | `string` | No | mergeable · conflicting · unknown | — |
| `pullRequest.githubSummary.Option 1.mergeQueued` | `boolean` | No | — | — |
| `pullRequest.githubSummary.Option 1.checks` | `object` | Yes | — | — |
| `pullRequest.githubSummary.Option 1.checks.total` | `integer` | Yes | min 0, max 9007199254740991 | — |
| `pullRequest.githubSummary.Option 1.checks.succeeded` | `integer` | Yes | min 0, max 9007199254740991 | — |
| `pullRequest.githubSummary.Option 1.checks.failing` | `integer` | Yes | min 0, max 9007199254740991 | — |
| `pullRequest.githubSummary.Option 1.checks.running` | `integer` | Yes | min 0, max 9007199254740991 | — |
| `pullRequest.githubSummary.Option 1.checksAvailable` | `boolean` | No | — | — |
| `pullRequest.githubSummary.Option 1.commentsAvailable` | `boolean` | No | — | — |
| `pullRequest.githubSummary.Option 1.unresolvedCount` | `integer` | Yes | min 0, max 9007199254740991 | — |
| `pullRequest.githubSummary.Option 2` | `null` | No | — | — |
| `pullRequest.githubSummaryUpdatedAt` | `string \| null` | No | — | — |

```json
{
  "ok": true,
  "pullRequest": {
    "id": "pr_example",
    "threadId": "thread_example",
    "number": 42,
    "url": "https://github.com/example/app/pull/42",
    "repoFullName": "example/app",
    "state": "open",
    "headRef": "hoplite/login-redirect",
    "headSha": "0123456789012345678901234567890123456789",
    "baseRef": "main",
    "draft": true
  }
}
```

## Response headers

| Header | Type | Statuses | Description |

| --- | --- | --- | --- |

| `RateLimit` | `string` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Current ingress policy, remaining requests, and seconds until reset, for example `"ingress";r=599;t=60`. |

| `RateLimit-Policy` | `string` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Ingress quota and window, for example `"ingress";q=600;qu="requests";w=60`. |

| `X-RateLimit-Limit` | `integer` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Maximum requests allowed in the current rolling window. |

| `X-RateLimit-Remaining` | `integer` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Requests remaining in the current rolling window. |

| `X-RateLimit-Reset` | `integer` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Unix timestamp when the current rolling window resets. |

| `x-request-id` | `string` | `201`, `400`, `401`, `402`, `403`, `404`, `409`, `410`, `429`, `500`, `501`, `503` | Request correlation ID. |

| `Retry-After` | `integer` | `429`, `503` | Seconds until another request should be attempted. |

| `X-Retry-After` | `integer` | `429`, `503` | Legacy retry delay in seconds. |

## Status codes

- `201` — Successful response

- `400` — Invalid request. Validation responses include field paths.

- `401` — The API key is missing, invalid, or lacks the operation's permission.

- `402` — The organization does not have access to the requested product capability.

- `403` — The key's current user no longer has the required organization membership or role.

- `404` — The resource is not available in the authenticated scope.

- `409` — The request conflicts with a retry receipt or current resource state.

- `410` — The event cursor has expired; capture a fresh head and resource snapshot.

- `429` — The API-key rate limit has been exceeded.

- `500` — The API encountered an unexpected failure.

- `501` — The deployment has not configured the requested capability.

- `503` — A required API dependency, including the rate limiter, is unavailable.