# Create a GitHub repository.

> Always an explicit action, never part of another: creates `owner/name` on GitHub, private unless `private: false`, with a README so it has a default branch: with the legacy personal token while it serves, or through the Koidog GitHub App (D89) in an organization whose installation grants `administration:write`, with a token asking for that permission alone, minted for this one call.
> https://koi.dog/docs/api/github/create-git-hub-repo/

`POST /api/v1/github/repos` · Scope: `config`

Through the App a personal account, or an organization that has not accepted `administration:write`, answers `403 missing_permission` and nothing is created. The workspace's owner only, signed in (never an API key or a limited CLI sign-in: `403 not_allowed`). Recorded on the timeline with who did it. `409 repo_exists` when the name is taken; `409 conflict` when the workspace's GitHub access changed during the request (the token replaced or removed, or the access that serves changed): nothing is created, try again; `403 missing_permission` when the access lacks a permission (the message names it) or, through the App, the account is a personal one; `409 github_access_required`, `503 github_unavailable`, `429 rate_limited` (at most 10 creations an hour per workspace). Answers the new repository. The timeline records the key ID, action and outcome.

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Retry the same request with the same key. [Retry rules](https://koi.dog/docs/api/#retries). |

## Body.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `owner` | `string` | yes | The account or organization to create it in: one of `GET /github/accounts` whose `canCreate` is not `no`. Matches `^[A-Za-z0-9](?:[A-Za-z0-9]\|-(?=[A-Za-z0-9])){0,38}$`. |
| `name` | `string` | yes | The new repository's name, as GitHub allows it: letters, digits, `.`, `-` and `_`. A name already taken in that account is `409 repo_exists`. Matches `^[A-Za-z0-9._-]{1,100}$`. |
| `private` | `boolean` | no | Left out or `true`, only people you give access can see it. `false` makes it public. Default `true`. |
| `description` | `string` | no | GitHub's one-line description of the repository, shown on GitHub. At most 350 characters. |

## Response.

201 Created · JSON object

- **422 validation_failed**: Each schema error appears in `details`.

## Request.

```sh
curl -X POST https://api.koi.dog/api/v1/github/repos \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{
      "owner": "<owner>",
      "name": "<name>"
    }'
```

```js
const res = await fetch("https://api.koi.dog/api/v1/github/repos", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    owner: "<owner>",
    name: "<name>",
  }),
});
console.log(await res.json());
```

```python
import os
import uuid

import requests

r = requests.post(
    "https://api.koi.dog/api/v1/github/repos",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "owner": "<owner>",
        "name": "<name>",
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "githubId": "string",
  "fullName": "string",
  "defaultBranch": "string",
  "private": false,
  "archived": false,
  "canPush": false,
  "pushedAt": "string",
  "description": "string"
}
```
