---
metadata:
  - name: generator
    content: Diplodoc Platform v5.70.2
alternate:
  - https://sourcecraft.dev/portal/docs/en/api-ref/User-or-Personal-access-tokens/CreatePAT.md
  - https://sourcecraft.dev/portal/docs/en/api-ref/User-or-Personal-access-tokens/CreatePAT.md
  - https://sourcecraft.dev/portal/docs/ru/api-ref/User-or-Personal-access-tokens/CreatePAT.md
  - href: https://sourcecraft.dev/portal/docs/en/api-ref/User-or-Personal-access-tokens/CreatePAT.md
    type: text/markdown
    title: Markdown version
  - href: https://sourcecraft.dev/portal/docs/en/llms.txt?revision=r22161526
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://sourcecraft.dev/portal/docs/en/llms.txt?revision=r22161526

<div class="openapi">

# Issue a personal access token for the authenticated subject.
Inherits all restrictions of the authenticating PAT, if any.
The token cannot outlive that PAT. JWT tokens expire within seven days;
named PV1 tokens expire within 365 days and appear in the user's token list.

<!-- markdownlint-disable-file -->

## Request

<div class="openapi__requests">

<div class="openapi__request__wrapper" style="--method: var(--dc-openapi-methods-post);margin-bottom: 12px">

<div class="openapi__request">

POST {.openapi__method}
```text translate=no
https://api.sourcecraft.tech/user/pats
```

</div>

</div>

</div>

<div class="openapi-entity">

### Body

{% cut "application/json" %}

```json translate=no
{
  "expires_at": "2025-01-01T00:00:00Z",
  "type": "jwt",
  "name": "example",
  "scope": {
    "role": "viewer",
    "repo_ids": [
      "example"
    ]
  }
}
```

{% endcut %}

#|
|| **Name** | **Description** ||
||

_expires_at_{.json-schema-reset .json-schema-property .json-schema-required}
{.table-cell}|
**Type**: string&lt;date-time&gt;

Required. Must be in the future, at most seven days (JWT) or 365 days (PV1)
from now, and no later than the expiration of the authenticating PAT.
Eternal tokens are not supported. Precision is rounded down to seconds.

_Example:_{.json-schema-reset .json-schema-example} `2025-01-01T00:00:00Z`
{.table-cell}
||
||

_name_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Required for PV1. The display name in the user's token list.
Optional for JWT; JWT tokens do not appear in that list.

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_scope_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: [CreatePATRequest.Scope](#entity-CreatePATRequest.Scope)

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
{
  "role": "viewer",
  "repo_ids": [
    "example"
  ]
}
```

{% endcut %}
{.table-cell}
||
||

_type_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: [TokenType](#entity-TokenType)

_Enum:_{.json-schema-reset .json-schema-value} `jwt`, `pv1`
{.table-cell}
||
|#{.json-schema-properties}

</div>

<div class="openapi-entity">

### TokenType {#entity-TokenType}

**Type**: string

_Enum:_{.json-schema-reset .json-schema-value} `jwt`, `pv1`

</div>

<div class="openapi-entity">

### RepoRole {#entity-RepoRole}

**Type**: string

_Enum:_{.json-schema-reset .json-schema-value} `viewer`, `contributor`, `developer`, `maintainer`, `admin`

</div>

<div class="openapi-entity">

### CreatePATRequest.Scope {#entity-CreatePATRequest.Scope}

#|
|| **Name** | **Description** ||
||

_repo_ids_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string[]

Public UUIDs of repositories to which the PAT is restricted (at most 100).
Empty means inherit the parent's objects, or all accessible repositories
when authenticating with IAM. Public repositories remain anonymously
readable unless the parent PAT disables anonymous-public access.

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
[
  "example"
]
```

{% endcut %}
{.table-cell}
||
||

_role_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: [RepoRole](#entity-RepoRole)

_Enum:_{.json-schema-reset .json-schema-value} `viewer`, `contributor`, `developer`, `maintainer`, `admin`
{.table-cell}
||
|#{.json-schema-properties}

{% cut "**Example**" %}{.json-schema-example}

```json translate=no
{
  "role": "viewer",
  "repo_ids": [
    "example"
  ]
}
```

{% endcut %}

</div>

## Responses

<div class="openapi__response__code__201">

## 201 Created

A successful response.

<div class="openapi-entity">

### Body

{% cut "application/json" %}

```json translate=no
{
  "token": "example",
  "expires_at": "2025-01-01T00:00:00Z",
  "type": "jwt"
}
```

{% endcut %}

#|
|| **Name** | **Description** ||
||

_expires_at_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string&lt;date-time&gt;

_Example:_{.json-schema-reset .json-schema-example} `2025-01-01T00:00:00Z`
{.table-cell}
||
||

_token_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

Credential. Returned only on creation.

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_type_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: [TokenType](#entity-TokenType)

_Enum:_{.json-schema-reset .json-schema-value} `jwt`, `pv1`
{.table-cell}
||
|#{.json-schema-properties}

</div>

</div>

<div class="openapi__response__code__default">

## default

Both Client Errors (4xx) and Server Errors (5xx) are serialized into this scheme

<div class="openapi-entity">

### Body

{% cut "application/json" %}

```json translate=no
{
  "error_code": "example",
  "message": "example",
  "request_id": "example",
  "details": null
}
```

{% endcut %}

#|
|| **Name** | **Description** ||
||

_details_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: unknown

_Example:_{.json-schema-reset .json-schema-example} `null`
{.table-cell}
||
||

_error_code_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_message_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
||

_request_id_{.json-schema-reset .json-schema-property}
{.table-cell}|
**Type**: string

_Example:_{.json-schema-reset .json-schema-example} `example`
{.table-cell}
||
|#{.json-schema-properties}

</div>

</div>

</div>

[*Deprecated]: No longer supported, please use an alternative and newer version.