---
title: "Create an access token"
method: POST
path: "/users/{username}/tokens"
tags: ["user"]
---

# Create an access token

`POST /users/{username}/tokens`

## Path parameters

- `username` string, required

## Request body

- CreateAccessTokenOption — CreateAccessTokenOption options when create access token
  - `name` string, required
  - `scopes` string[]

## Response `201`

AccessToken represents an API access token.

- AccessToken
  - `created_at` string, date-time — The timestamp when the token was created
  - `id` integer — The unique identifier of the access token
  - `last_used_at` string, date-time — The timestamp when the token was last used
  - `name` string — The name of the access token
  - `scopes` string[] — The scopes granted to this access token
  - `sha1` string — The SHA1 hash of the access token
  - `token_last_eight` string — The last eight characters of the token

## Other responses

- `400` — APIError is error format response
- `403` — APIForbiddenError is a forbidden error response

---

[API](https://skmtc.net/gitea/apis/gitea-api.md) · [All operations](https://skmtc.net/gitea/apis/gitea-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/gitea/gitea-api/revisions/350de506cefa/schema)
